-
Notifications
You must be signed in to change notification settings - Fork 30
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
Handle #[codec(index = …)]
in regular enums
#80
Conversation
By default, parity-scale-codec does not provide Encode/Decode impls for an owned String. This is only provided under the "full" feature which is not used by the substrate runtime, because it should not be used for consensus critical code. So in order for the CompactForm to be integrated into the substrate runtime, or wherever the "full" feature cannot be used, then we must parameterize the `String` type so that it can be both an `&'static str` on the runtime side where it is encoded, and a `String` in client/consuming code where it is decoded.
Add a `compact` member to `Field` to indicate it is `scale_codec::Compact`
…ncoded/decoded as a SCALE Compact type
Handle `codec(skip)` and `codec(index = $int)` attributes
Ensure we're working with an outer attribute
Co-authored-by: Robin Freyler <[email protected]>
match v.fields { | ||
let v_name = quote! {::core::stringify!(#ident) }; | ||
let docs = utils::get_doc_literals(&v.attrs); | ||
let index = utils::maybe_index(v).map(|i| quote!(.index(#i))); |
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.
It's hard to overstate how much nicer this is compared to what I had.
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.
That was one of my goals with the builder pattern changes, so thanks!, The main priorities being type safe construction and friendliness for the derive macro. The tradeoff being that it is not fantastic for constructing type infos by hand, but we are assuming that is not very common.
* Capture docs for types, fields, and enum variants * Add docs to derive tests * Fmt * Fmt * Make clippy happy * Fix struct docs tests * Fix struct docs tests * Add missing Vec import * Fix test * Clear docs * Promote build to it's own mod, split fields and variant builders * Refactor variant construction with builder * Fix up derive and unit tests with Variant builder * Fmt * Condense build module back to single file * Fix up doc tests * Fix up README * Define initial field builder * Fix up field building * Fix tests * Fully qualify calls to stringify * Default impl for FieldBuilder * Fix up default impl * Fix spelling errors * Remove clear_docs * Fully qualify module_path * Update derive/src/lib.rs Co-authored-by: Robin Freyler <[email protected]> * Use callback for variant builder * Update README * Remove leading space in doc comments * Satisfy clippy * Add test for doc capture * Rename index back to discriminant, changes for this will be in #80 * Rename index back to discriminant, changes for this will be in #80 * Update src/build.rs Co-authored-by: David <[email protected]> * Update src/build.rs Co-authored-by: David <[email protected]> Co-authored-by: Robin Freyler <[email protected]> Co-authored-by: David <[email protected]>
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.
LGTM
match v.fields { | ||
let v_name = quote! {::core::stringify!(#ident) }; | ||
let docs = utils::get_doc_literals(&v.attrs); | ||
let index = utils::maybe_index(v).map(|i| quote!(.index(#i))); |
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.
That was one of my goals with the builder pattern changes, so thanks!, The main priorities being type safe construction and friendliness for the derive macro. The tradeoff being that it is not fantastic for constructing type infos by hand, but we are assuming that is not very common.
A Variant can have fields of 3 different kinds:
Named
,Unnamed
orUnit
. In this PR I introduce indexed variations of these, so we haveVariantsBuilder::variant
/VariantsBuilder::indexed_variant
andVariantsBuilder::variant_unit
/VariantsBuilder::indexed_variant_unit
.This PR stores the index in a new
index
member ofVariant
, which is probably a bit contentious given it increases the size of the registry.We could also store the index in the
discriminant
field, which would be compatible with the direction the Rust language is heading with RFC 2363 (surfacing discriminants for all enum variants, c-style or not).It is currently possible to set both the discriminant and the index on a c-style enum (with priority given to the index attribute):
I think that the more cautious path is to have both
index
anddiscriminant
, mimicingparity-scale-info
s behaviour.Builds on top of #44
Closes #79