-
Notifications
You must be signed in to change notification settings - Fork 28
Add a TypeDef to handle Compact types #53
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
Changes from all commits
37c0a57
643f09d
9a7ccbf
254fee1
e74e4f9
7860c79
579f958
8333e5a
2818f7b
7706a38
e03a2cd
3a95663
004e107
93a9aeb
6569e50
f098101
eda2769
09c1241
55f1413
e2397bf
d15bf25
1f4f8d3
02ed1a3
80a8b27
7389297
d8506dc
ab56118
5436755
c70f31c
e656489
1c0c05d
693b23a
c2a38f5
5649a66
aad3277
4b18500
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -51,10 +51,21 @@ pub fn make_where_clause<'a>( | |
|
|
||
| let types = collect_types_to_bind(input_ident, data, &ty_params_ids)?; | ||
|
|
||
| types.into_iter().for_each(|ty| { | ||
| where_clause | ||
| .predicates | ||
| .push(parse_quote!(#ty : ::scale_info::TypeInfo + 'static)) | ||
| types.into_iter().for_each(|(ty, is_compact)| { | ||
| // Compact types need extra bounds, T: HasCompact and <T as | ||
| // HasCompact>::Type: TypeInfo + 'static | ||
| if is_compact { | ||
| where_clause | ||
| .predicates | ||
| .push(parse_quote!(#ty : ::scale::HasCompact)); | ||
| where_clause | ||
| .predicates | ||
| .push(parse_quote!(<#ty as ::scale::HasCompact>::Type : ::scale_info::TypeInfo + 'static)); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think our use of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this also seem to break primitive-types: paritytech/parity-common#519 |
||
| } else { | ||
| where_clause | ||
| .predicates | ||
| .push(parse_quote!(#ty : ::scale_info::TypeInfo + 'static)); | ||
| } | ||
| }); | ||
|
|
||
| generics.type_params().into_iter().for_each(|type_param| { | ||
|
|
@@ -94,14 +105,14 @@ fn type_contains_idents(ty: &Type, idents: &[Ident]) -> bool { | |
| visitor.result | ||
| } | ||
|
|
||
| /// Returns all types that must be added to the where clause with the respective | ||
| /// trait bound. | ||
| /// Returns all types that must be added to the where clause with a boolean | ||
| /// indicating if the field is [`scale::Compact`] or not. | ||
| fn collect_types_to_bind( | ||
| input_ident: &Ident, | ||
| data: &syn::Data, | ||
| ty_params: &[Ident], | ||
| ) -> Result<Vec<Type>> { | ||
| let types_from_fields = |fields: &Punctuated<syn::Field, _>| -> Vec<syn::Type> { | ||
| ) -> Result<Vec<(Type, bool)>> { | ||
| let types_from_fields = |fields: &Punctuated<syn::Field, _>| -> Vec<(Type, bool)> { | ||
| fields | ||
| .iter() | ||
| .filter(|field| { | ||
|
|
@@ -112,7 +123,7 @@ fn collect_types_to_bind( | |
| // to not have them in the where clause. | ||
| !type_contains_idents(&field.ty, &[input_ident.clone()]) | ||
| }) | ||
| .map(|f| f.ty.clone()) | ||
| .map(|f| (f.ty.clone(), super::is_compact(f))) | ||
| .collect() | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -270,7 +270,6 @@ mod tests { | |
| "&mut RecursiveRefs", | ||
| ), | ||
| ) | ||
| .into() | ||
| } | ||
| } | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.