-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: bounds for ser/de derive and schema_params for schema derive attributes #180
Conversation
…and use in derive of `Ser/De`
…of params in generics
7377ea2
to
1f1a8f4
Compare
C: borsh::BorshSchema, | ||
{ | ||
fn declaration() -> borsh::schema::Declaration { | ||
let params = borsh::__private::maybestd::vec![< C > ::declaration()]; | ||
let params = borsh::__private::maybestd::vec![ | ||
< U > ::declaration(), < C > ::declaration() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the order has been changed to follow not alphabetic order of types transcription, but
the original order of generics declaration in this commit (as compared to master the pr is being merged on)
…s to simplify future unsplit
…structs [✓] cleaning of traits of generics for inner structs ├── [✓] remove cleaning of associated bounds on params in impl block └── [✓] implement filtering of where predicates used for not-skipped params (they were removed altogether previously)
e778d2f
to
f9ff26e
Compare
Despite work in this commit on filtering relevant fn test_enum_with_lifetimes() {
#[allow(unused)]
#[derive(borsh::BorshSchema)]
enum EnumParametrized<'a, 'b, T, V>
{
A {
x: BTreeMap<u16, &'a T>,
},
B(&'b V, u16),
}
} error[E0392]: parameter `'b` is never used
--> borsh/tests/test_schema_enums.rs:359:31
|
359 | enum EnumParametrized<'a, 'b, T, V>
| ^^ unused parameter
|
= help: consider removing `'b`, referring to it in a field, or using a marker such as `PhantomData`
error[E0392]: parameter `'a` is never used
--> borsh/tests/test_schema_enums.rs:359:27
|
359 | enum EnumParametrized<'a, 'b, T, V>
| ^^ unused parameter
|
= help: consider removing `'a`, referring to it in a field, or using a marker such as `PhantomData` One way to amend this might be to add yet one more attribute to hint relevant generics to derive: #[test]
fn test_enum_with_lifetimes() {
#[allow(unused)]
#[derive(borsh::BorshSchema)]
enum EnumParametrized<'a, 'b, T, V>
{
#[borsh(schema(variant_generics = "'a, T"))]
A {
x: BTreeMap<u16, &'a T>,
},
#[borsh(schema(variant_generics = "'b, V"))]
B(&'b V, u16),
}
} Leaving it as is as of now (not adding 1 error[E0392]: parameter `'b` is never used
--> borsh/tests/test_schema_enums.rs:218:31
2 error[E0392]: parameter `'a` is never used
--> borsh/tests/test_schema_enums.rs:218:27 |
5aff41e
to
c1d6383
Compare
@iho the following files have been made identical, these contain some functionality shared between
|
d90216f
to
8368ed1
Compare
be69381
to
34c77a8
Compare
34c77a8
to
6fca9f0
Compare
This is logical continuation/conclusion of #178 .
Pr adds possibility to override bounds for BorshSerialize and BorshDeserialize in order to allow not to keep
bounds on type parameters in struct definition itself and fix complex cases, when derive hasn't figured
the right bounds on type parameters automatically, while still not having to implement the traits manually.
Pr also adds
#[borsh(schema(params = ...))]
attribute, which may be populated by a list of entries.order_param => override_type
.Such an entry instructs
BorshSchema
derive to:override_type
to types, bounded byborsh::BorshSchema
in implementation block.<override_type>::declaration()
to parameters vector infn declaration()
method ofBorshSchema
trait that is being derived.order_param
is required to establish the same order in parameters vector (2.) as that of type parameters in generics of type, thatBorshSchema
is derived for.