From 9261b1eed718df4371a0c8d3a1b5ec5fd2a33565 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 25 Aug 2021 08:34:21 +0100 Subject: [PATCH 1/4] Move Range variant to the end of the type enum for backwards compat --- src/ty/mod.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/ty/mod.rs b/src/ty/mod.rs index cc328cf3..19384720 100644 --- a/src/ty/mod.rs +++ b/src/ty/mod.rs @@ -247,14 +247,14 @@ pub enum TypeDef { Array(TypeDefArray), /// A tuple type. Tuple(TypeDefTuple), - /// A Range type. - Range(TypeDefRange), /// A Rust primitive type. Primitive(TypeDefPrimitive), /// A type using the [`Compact`] encoding Compact(TypeDefCompact), /// A type representing a sequence of bits. BitSequence(TypeDefBitSequence), + /// A Range type. + Range(TypeDefRange), } impl IntoPortable for TypeDef { @@ -267,10 +267,10 @@ impl IntoPortable for TypeDef { TypeDef::Sequence(sequence) => sequence.into_portable(registry).into(), TypeDef::Array(array) => array.into_portable(registry).into(), TypeDef::Tuple(tuple) => tuple.into_portable(registry).into(), - TypeDef::Range(range) => range.into_portable(registry).into(), TypeDef::Primitive(primitive) => primitive.into(), TypeDef::Compact(compact) => compact.into_portable(registry).into(), TypeDef::BitSequence(bitseq) => bitseq.into_portable(registry).into(), + TypeDef::Range(range) => range.into_portable(registry).into(), } } } From 10111bccf31c7e461e5b37f5b4416ea40d9f5395 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 25 Aug 2021 08:39:27 +0100 Subject: [PATCH 2/4] Bump versions and update CHANGELOG.md --- CHANGELOG.md | 5 +++++ Cargo.toml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b41ce4ad..62a6cde3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.11.0] - 2021-08-25 +### Added +- Add type parameter getters [(#122)](https://github.com/paritytech/scale-info/pull/122) +- Add support for Range and RangeInclusive [(#124)](https://github.com/paritytech/scale-info/pull/124), [(#126)](https://github.com/paritytech/scale-info/pull/126) + ## [0.10.0] - 2021-07-29 ### Added - Add capture_docs attribute [(#118)](https://github.com/paritytech/scale-info/pull/118) diff --git a/Cargo.toml b/Cargo.toml index e7264a84..a39d5a68 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "scale-info" -version = "0.10.0" +version = "0.11.0" authors = ["Parity Technologies "] edition = "2018" From 175f80f16bbf570a6d350ee23efee7db8922bdfb Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 25 Aug 2021 10:12:21 +0100 Subject: [PATCH 3/4] Add explicit enum indices --- src/ty/mod.rs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/ty/mod.rs b/src/ty/mod.rs index 19384720..03e68391 100644 --- a/src/ty/mod.rs +++ b/src/ty/mod.rs @@ -225,6 +225,16 @@ where } /// The possible types a SCALE encodable Rust value could have. +/// +/// # Note +/// +/// In order to preserve backwards compatibility, variant indices are explicitly specified instead +/// of depending on the default implicit ordering. +/// +/// When adding a new variant, it must be added at the end with an incremented index. +/// +/// When removing an existing variant, the rest of variant indices remain the same, and the removed +/// index should not be reused. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde", @@ -238,22 +248,31 @@ where #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, From, Debug, Encode)] pub enum TypeDef { /// A composite type (e.g. a struct or a tuple) + #[codec(index = 0)] Composite(TypeDefComposite), /// A variant type (e.g. an enum) + #[codec(index = 1)] Variant(TypeDefVariant), /// A sequence type with runtime known length. + #[codec(index = 2)] Sequence(TypeDefSequence), /// An array type with compile-time known length. + #[codec(index = 3)] Array(TypeDefArray), /// A tuple type. + #[codec(index = 4)] Tuple(TypeDefTuple), /// A Rust primitive type. + #[codec(index = 5)] Primitive(TypeDefPrimitive), /// A type using the [`Compact`] encoding + #[codec(index = 6)] Compact(TypeDefCompact), /// A type representing a sequence of bits. + #[codec(index = 7)] BitSequence(TypeDefBitSequence), /// A Range type. + #[codec(index = 8)] Range(TypeDefRange), } @@ -276,40 +295,59 @@ impl IntoPortable for TypeDef { } /// A primitive Rust type. +/// +/// # Note +/// +/// Explicit codec indices specified to ensure backwards compatibility. See [`TypeDef`]. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", serde(rename_all = "lowercase"))] #[cfg_attr(any(feature = "std", feature = "decode"), derive(scale::Decode))] #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Debug)] pub enum TypeDefPrimitive { /// `bool` type + #[codec(index = 0)] Bool, /// `char` type + #[codec(index = 1)] Char, /// `str` type + #[codec(index = 2)] Str, /// `u8` + #[codec(index = 3)] U8, /// `u16` + #[codec(index = 4)] U16, /// `u32` + #[codec(index = 5)] U32, /// `u64` + #[codec(index = 6)] U64, /// `u128` + #[codec(index = 7)] U128, /// 256 bits unsigned int (no rust equivalent) + #[codec(index = 8)] U256, /// `i8` + #[codec(index = 9)] I8, /// `i16` + #[codec(index = 10)] I16, /// `i32` + #[codec(index = 11)] I32, /// `i64` + #[codec(index = 12)] I64, /// `i128` + #[codec(index = 13)] I128, /// 256 bits signed int (no rust equivalent) + #[codec(index = 14)] I256, } From 33f7037ab0c16f6fd2ac77cb4e9e035264d303a5 Mon Sep 17 00:00:00 2001 From: Andrew Jones Date: Wed, 25 Aug 2021 10:14:37 +0100 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62a6cde3..98ac6514 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Add type parameter getters [(#122)](https://github.com/paritytech/scale-info/pull/122) - Add support for Range and RangeInclusive [(#124)](https://github.com/paritytech/scale-info/pull/124), [(#126)](https://github.com/paritytech/scale-info/pull/126) +- Explicit codec indices for `TypeDef` and `TypeDefPrimitive` enums [(#127)](https://github.com/paritytech/scale-info/pull/127) ## [0.10.0] - 2021-07-29 ### Added