Skip to content

Commit

Permalink
Merge branch 'master' into dz/2
Browse files Browse the repository at this point in the history
  • Loading branch information
dzmitry-lahoda authored Nov 3, 2024
2 parents 58b8b14 + 21c024f commit 910bb08
Show file tree
Hide file tree
Showing 5 changed files with 357 additions and 2 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ enum A {
}
```

## Advanced examples

Some of the less trivial examples are present in [examples](./borsh/examples) folder:

- [implementing `BorshSerialize`/`BorshDeserialize` for third-party `serde_json::Value`](./borsh/examples/serde_json_value.rs)

## Testing

Integration tests should generally be preferred to unit ones. Root module of integration tests of `borsh` crate is [linked](./borsh/tests/tests.rs) here.
Expand Down
4 changes: 3 additions & 1 deletion borsh-derive/src/internals/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ impl FindTyParams {
)]
match bound {
TypeParamBound::Trait(bound) => self.visit_path(&bound.path),
TypeParamBound::Lifetime(_) | TypeParamBound::Verbatim(_) => {}
TypeParamBound::Lifetime(_)
| TypeParamBound::Verbatim(_)
| TypeParamBound::PreciseCapture(_) => {}
_ => {}
}
}
Expand Down
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
5 changes: 5 additions & 0 deletions borsh/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ exclude = ["*.snap"]
name = "borsh"
path = "src/lib.rs"

[[example]]
name = "serde_json_value"
required-features = ["std", "derive"]

[[bin]]
name = "generate_schema_schema"
path = "src/generate_schema_schema.rs"
Expand All @@ -39,6 +43,7 @@ bson = { version = "2", optional = true }

[dev-dependencies]
insta = "1.29.0"
serde_json = { version = "1" }

[package.metadata.docs.rs]
features = ["derive", "unstable__schema", "rc"]
Expand Down
Loading

0 comments on commit 910bb08

Please sign in to comment.