Skip to content

Commit

Permalink
doc: add reference from serialize_with/deserialize_with attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
dj8yf0μl committed Oct 29, 2024
1 parent 9df3223 commit 6f0ae64
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
11 changes: 10 additions & 1 deletion borsh-derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,15 @@ struct B<K, V> {
}
```
###### usage (comprehensive example)
[borsh/examples/serde_json_value.rs](https://github.com/near/borsh-rs/blob/master/borsh/examples/serde_json_value.rs) is
a more complex example of how the attribute may be used.
###### interaction with `#[borsh(skip)]`
`#[borsh(serialize_with = ...)]` is not allowed to be used simultaneously with `#[borsh(skip)]`.
*/
#[proc_macro_derive(BorshSerialize, attributes(borsh))]
pub fn borsh_serialize(input: TokenStream) -> TokenStream {
Expand Down Expand Up @@ -622,6 +626,11 @@ struct B<K: Hash + Eq, V> {
}
```
###### usage (comprehensive example)
[borsh/examples/serde_json_value.rs](https://github.com/near/borsh-rs/blob/master/borsh/examples/serde_json_value.rs) is
a more complex example of how the attribute may be used.
###### interaction with `#[borsh(skip)]`
`#[borsh(deserialize_with = ...)]` is not allowed to be used simultaneously with `#[borsh(skip)]`.
Expand Down
1 change: 1 addition & 0 deletions borsh/examples/serde_json_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ mod serde_json_value {
BorshDeserialize,
};

/// this is copy-paste of https://github.com/near/borsh-rs/blob/master/borsh/src/de/hint.rs#L2-L5
fn hint_cautious<T>(hint: u32) -> usize {
let el_size = core::mem::size_of::<T>() as u32;
core::cmp::max(core::cmp::min(hint, 4096 / el_size), 1) as usize
Expand Down

0 comments on commit 6f0ae64

Please sign in to comment.