-
Notifications
You must be signed in to change notification settings - Fork 451
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
Enable ink_metadata
to be used for metadata generation outside of ink!
#1357
Merged
Merged
Changes from 16 commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
98fc658
switch API to support string, expose more generic constructors and bu…
xermicus 29f1740
this is not needed
xermicus defcbc1
Merge branch 'master' into cl/runtime-metadata
xermicus 85ce4f7
Merge branch 'master' into cl/runtime-metadata
xermicus c980a89
patch scale-info dep
xermicus e44b706
clippy happy
xermicus 98b43e1
Merge branch 'master' into cl/runtime-metadata
xermicus 5427347
patch scale-info dep to current dev branch
xermicus fec263b
WIP adapting for changes in scale-info
xermicus 494d9a3
clippy
xermicus 61b82f3
point to scale-info master
xermicus 98d093b
Merge branch 'master' into cl/runtime-metadata
xermicus 9553e49
more generic root layout constructor
xermicus 5a5f44c
Merge branch 'master' into cl/runtime-metadata
xermicus d936040
test future version of scale-info
xermicus df2baee
nigthly fmt
xermicus a4fe8f5
make spec fields private again
xermicus b480e4d
Merge branch 'master' into cl/runtime-metadata
xermicus aae6fa4
new_custom for ReturnTypeSpec
xermicus d10f31d
Merge branch 'master' into cl/runtime-metadata
xermicus f7556d6
yay scale-info release
xermicus dd2f2d7
tidy up some constructors
xermicus d385e16
getting rid of DocString trait
xermicus 8ca76e9
generic type specs constructors
xermicus bd2f379
TypeSpec::new renamed to TypeSpec::of_type
xermicus c658c46
Merge branch 'master' into cl/runtime-metadata
xermicus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,6 +106,14 @@ impl<'a> From<&'a Key> for LayoutKey { | |
} | ||
|
||
impl LayoutKey { | ||
/// Construct a custom layout key. | ||
pub fn new<T>(key: T) -> Self | ||
where | ||
T: Into<u32>, | ||
{ | ||
Self { key: key.into() } | ||
} | ||
|
||
/// Returns the key of the layout key. | ||
pub fn key(&self) -> &Key { | ||
&self.key | ||
|
@@ -125,19 +133,6 @@ pub struct RootLayout<F: Form = MetaForm> { | |
layout: Box<Layout<F>>, | ||
} | ||
|
||
impl RootLayout { | ||
/// Creates a new root layout. | ||
pub fn new<L>(root_key: LayoutKey, layout: L) -> Self | ||
where | ||
L: Into<Layout>, | ||
{ | ||
Self { | ||
root_key, | ||
layout: Box::new(layout.into()), | ||
} | ||
} | ||
} | ||
|
||
impl IntoPortable for RootLayout { | ||
type Output = RootLayout<PortableForm>; | ||
|
||
|
@@ -153,6 +148,17 @@ impl<F> RootLayout<F> | |
where | ||
F: Form, | ||
{ | ||
/// Creates a new root layout. | ||
pub fn new<L>(root_key: LayoutKey, layout: L) -> Self | ||
where | ||
L: Into<Layout<F>>, | ||
{ | ||
Self { | ||
root_key, | ||
layout: Box::new(layout.into()), | ||
} | ||
} | ||
|
||
/// Returns the root key of the sub-tree. | ||
pub fn root_key(&self) -> &LayoutKey { | ||
&self.root_key | ||
|
@@ -241,6 +247,10 @@ where | |
pub fn ty(&self) -> &F::Type { | ||
&self.ty | ||
} | ||
|
||
pub fn new_from_ty(key: LayoutKey, ty: <F as Form>::Type) -> Self { | ||
Self { key, ty } | ||
} | ||
} | ||
|
||
/// A hashing layout potentially hitting all cells of the storage. | ||
|
@@ -448,24 +458,22 @@ pub struct StructLayout<F: Form = MetaForm> { | |
fields: Vec<FieldLayout<F>>, | ||
} | ||
|
||
impl StructLayout { | ||
impl<F> StructLayout<F> | ||
where | ||
F: Form, | ||
{ | ||
/// Creates a new struct layout. | ||
pub fn new<N, F>(name: N, fields: F) -> Self | ||
pub fn new<N, T>(name: N, fields: T) -> Self | ||
where | ||
N: Into<&'static str>, | ||
F: IntoIterator<Item = FieldLayout>, | ||
N: Into<F::String>, | ||
T: IntoIterator<Item = FieldLayout<F>>, | ||
{ | ||
Self { | ||
name: name.into(), | ||
fields: fields.into_iter().collect(), | ||
} | ||
} | ||
} | ||
|
||
impl<F> StructLayout<F> | ||
where | ||
F: Form, | ||
{ | ||
/// Returns the name of the struct. | ||
pub fn name(&self) -> &F::String { | ||
&self.name | ||
|
@@ -481,7 +489,7 @@ impl IntoPortable for StructLayout { | |
|
||
fn into_portable(self, registry: &mut Registry) -> Self::Output { | ||
StructLayout { | ||
name: self.name.into(), | ||
name: self.name.to_string(), | ||
fields: self | ||
.fields | ||
.into_iter() | ||
|
@@ -511,7 +519,7 @@ impl FieldLayout { | |
/// Creates a new field layout. | ||
pub fn new<N, L>(name: N, layout: L) -> Self | ||
where | ||
N: Into<&'static str>, | ||
N: Into<<MetaForm as Form>::String>, | ||
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 we should just use this constructor and make it generic over form, and remove |
||
L: Into<Layout>, | ||
{ | ||
Self { | ||
|
@@ -525,6 +533,17 @@ impl<F> FieldLayout<F> | |
where | ||
F: Form, | ||
{ | ||
/// Creates a new custom field layout. | ||
pub fn new_custom<N, L>(name: N, layout: L) -> Self | ||
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. Remove this in favour of generic |
||
where | ||
N: Into<F::String>, | ||
L: Into<Layout<F>>, | ||
{ | ||
Self { | ||
name: name.into(), | ||
layout: layout.into(), | ||
} | ||
} | ||
/// Returns the name of the field. | ||
pub fn name(&self) -> &F::String { | ||
&self.name | ||
|
@@ -544,7 +563,7 @@ impl IntoPortable for FieldLayout { | |
|
||
fn into_portable(self, registry: &mut Registry) -> Self::Output { | ||
FieldLayout { | ||
name: self.name.into_portable(registry), | ||
name: self.name.to_string(), | ||
layout: self.layout.into_portable(registry), | ||
} | ||
} | ||
|
@@ -587,7 +606,7 @@ impl EnumLayout { | |
/// Creates a new enum layout. | ||
pub fn new<N, K, V>(name: N, dispatch_key: K, variants: V) -> Self | ||
where | ||
N: Into<&'static str>, | ||
N: Into<<MetaForm as Form>::String>, | ||
K: Into<LayoutKey>, | ||
V: IntoIterator<Item = (Discriminant, StructLayout)>, | ||
{ | ||
|
@@ -624,7 +643,7 @@ impl IntoPortable for EnumLayout { | |
|
||
fn into_portable(self, registry: &mut Registry) -> Self::Output { | ||
EnumLayout { | ||
name: self.name.into(), | ||
name: self.name.to_string(), | ||
dispatch_key: self.dispatch_key, | ||
variants: self | ||
.variants | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
I think this constructor should become
new
because it allows setting all fields. The existingnew<T>
can be renamed tofrom_key<T>
or similar to be consistent.