Comments (8)
Frankly speaking this is illuminating
video_2023-12-13_17-22-28.mp4
from borsh-rs.
it probably should've been
fn deserialize_reader<R: Read>(mut reader: R) -> Result<Self>;
Does this change allow any wider use cases for the traits?
I believe both signatures are equivalent with respect to how the traits can be used in practice, and mutable reference argument better reflects semantics of what the traits are doing: they borrow Reader/Writer for de/ser of one object and return it intact to the caller (by-value argument drops Reader/Writer after one object).
from borsh-rs.
It probably should've been
fn deserialize_reader<R: Read>(mut reader: R) -> Result<Self>;
No. You do not need to specify mut in the trait definition itself, only in the implementation. See playground link below.
Does this change allow any wider use cases for the traits?
It's somewhat weird that you have to pass a mutable reference to a immutable buffer when you're deserializing. See playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dd2f2606d714535fbba3e5e5b00208cc
mutable reference argument better reflects semantics of what the traits are doing
Yes. But if your writer is a mutable reference itself then it makes sense for the mutable reference to be dropped after one object, does it not?
For reference: serde_json
also bounds most stuff by W
and R
instead of &mut W
and &mut R
https://docs.rs/serde_json/latest/serde_json/fn.to_writer.html , https://docs.rs/serde_json/latest/serde_json/fn.from_reader.html
from borsh-rs.
It's somewhat weird that you have to pass a mutable reference to a immutable buffer when you're deserializing
these are playground examples for Read and Write
https://doc.rust-lang.org/src/std/io/impls.rs.html#248
from borsh-rs.
I believe Rust API guidelines recommends to pass Read
and Write
by value: https://rust-lang.github.io/api-guidelines/interoperability.html#generic-readerwriter-functions-take-r-read-and-w-write-by-value-c-rw-value
Regarding the playground examples, I think this is what by_ref() is for. Read example fixed, Write example fixed
from borsh-rs.
More info here: rust-lang/api-guidelines#174
from borsh-rs.
So, do you guys intend to change this for 2.0? I also wanna add that this issue has surfaced before: #34
from borsh-rs.
@billythedummy Thank you for raising it
So, do you guys intend to change this for 2.0?
We don't intent to release 2.0 any time soon unless there is a very good reason to. I have created a tracking issue for the ideas that would require us to bump the major version here: #279
from borsh-rs.
Related Issues (20)
- Restriction on Serializing Zero-Sized Types Affects Marker Component Usage HOT 7
- derive BoshSerialize fails if the type already uses `W` generic name HOT 4
- BorshSerialize derive fails for structs with packed attribute HOT 4
- Should `std` feature imply `rc` feature and vice-versa? HOT 4
- `derive` macros require `cargo` to be present HOT 4
- Old NEAR contracts won't compile with the new `borsh` re-exported from `near-sdk-rs` ("Could not find `borsh`") HOT 5
- equivalent of `#[serde(default)]` HOT 2
- Borsh 2.0? Not planned HOT 2
- Extract `alloc` feature (2.0 candidate) HOT 1
- `bytes::Bytes` and `bytes::BytesMut` can be complemented with `BorshSchema`
- `bson::oid::ObjectId` can be complemented with `BorshSchema`
- Add struct/enum attr to relax bounds
- feat(schema): for chars HOT 4
- feat(schema): support serde of HashMap with S hasher
- Support for adding new fields to previously serialized structs HOT 2
- Can't serialize a `Vec<ZST>`, but it appears that the attack is only on deserialization HOT 1
- blanket implementation of `BorshSchema` for `&T` (where `T: BorshSchema`)
- Replace `schema_map!` tests with `insta` snapshots
- Backport Vec<ZST> deserialisation fix to 0.10.x HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from borsh-rs.