-
Notifications
You must be signed in to change notification settings - Fork 28
Add a compact flag to Field
#42
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 1 commit
37c0a57
643f09d
9a7ccbf
254fee1
e74e4f9
7860c79
579f958
8333e5a
2818f7b
7706a38
e03a2cd
3a95663
004e107
93a9aeb
6569e50
f098101
eda2769
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
compact flag to Field to indicate that this type is to be e…
…ncoded/decoded as a SCALE Compact type
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -303,7 +303,6 @@ mod tests { | |
| "&mut RecursiveRefs", | ||
| ), | ||
| ) | ||
| .into() | ||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -86,6 +86,14 @@ pub struct Field<T: Form = MetaForm> { | |
| ty: T::Type, | ||
| /// The name of the type of the field as it appears in the source code. | ||
| type_name: T::String, | ||
| /// This field should be encode/decoded as a | ||
| /// [`Compact`](parity_scale_codec::Compact) field | ||
| #[cfg_attr(feature = "serde", serde(skip_serializing_if = "is_false", default))] | ||
| compact: bool, | ||
|
Comment on lines
+89
to
+92
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 an even more compact representation for the exact same use case would be to use yet another enum variant in order to represent compacted types. The idea is to add another variant pub struct TypeDefCompact<T>
where
T: Form = MetaForm
{
#[serde(rename = "type")]
type_param: T::Type,
}Then instead of requiring each type to have this
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. At first glance I think this solution is more elegant than having the field, while still making it a first class citizen (unlike just using a type e.g. |
||
| } | ||
|
|
||
| fn is_false(v: &bool) -> bool { | ||
| !v | ||
| } | ||
|
|
||
| impl IntoFrozen for Field { | ||
|
|
@@ -96,6 +104,7 @@ impl IntoFrozen for Field { | |
| name: self.name.map(|name| name.into_frozen(registry)), | ||
| ty: registry.register_type(&self.ty), | ||
| type_name: self.type_name.into_frozen(registry), | ||
| compact: self.compact, | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -108,11 +117,13 @@ impl Field { | |
| name: Option<&'static str>, | ||
| ty: MetaType, | ||
| type_name: &'static str, | ||
| compact: bool, | ||
| ) -> Self { | ||
| Self { | ||
| name, | ||
| ty, | ||
| type_name, | ||
| compact, | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -124,7 +135,7 @@ impl Field { | |
| where | ||
| T: TypeInfo + ?Sized + 'static, | ||
| { | ||
| Self::new(Some(name), MetaType::new::<T>(), type_name) | ||
| Self::new(Some(name), MetaType::new::<T>(), type_name, false) | ||
| } | ||
|
|
||
| /// Creates a new unnamed field. | ||
|
|
@@ -135,7 +146,7 @@ impl Field { | |
| where | ||
| T: TypeInfo + ?Sized + 'static, | ||
| { | ||
| Self::new(None, MetaType::new::<T>(), type_name) | ||
| Self::new(None, MetaType::new::<T>(), type_name, false) | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -161,4 +172,10 @@ where | |
| pub fn type_name(&self) -> &T::String { | ||
| &self.type_name | ||
| } | ||
|
|
||
| /// Set the `compact` property to true, signalling that this type is to be | ||
| /// encoded/decoded as a [`parity_scale_codec::Compact`]. | ||
| pub fn compact(&mut self) { | ||
| self.compact = true; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.