Conversation
| /// Returns the index of the variant, if specified. | ||
| pub fn index(&self) -> Option<u8> { | ||
| self.index | ||
| } |
There was a problem hiding this comment.
What is the difference here from the discriminant?
There was a problem hiding this comment.
The discriminant is only valid for "C Like" enums.
If both are specified then the index takes precedence for encoding. We still retain the discriminant though for e.g. reconstructing the original type.
There was a problem hiding this comment.
Ah okay I see. Although we should keep in mind that there is a Rust RFC to allow for discriminants for data variants. Although then #[scale(index = N)] would still override those which should be fine.
There was a problem hiding this comment.
Yes that would still hold true. You are correct that index specifically refers to the value from the attribute. And it can be different from the discriminator, but will take precedence for encoding.
There was a problem hiding this comment.
keep in mind that there is a Rust RFC
If/when that lands and is stabilised we could deprecate the #[scale(index = N)] attribute and only use discriminants. That would be nice (and a breaking change both to us and parity-scale-codec).
| } | ||
|
|
||
| /// Returns the index of the variant. | ||
| /// Returns the index of the variant, if specified. |
No description provided.