Skip to content

Commit

Permalink
Release v0.11.0 (#127)
Browse files Browse the repository at this point in the history
* Move Range variant to the end of the type enum for backwards compat

* Bump versions and update CHANGELOG.md

* Add explicit enum indices

* Update CHANGELOG.md
  • Loading branch information
ascjones authored Aug 25, 2021
1 parent 56d24a2 commit a028631
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ 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)
- Explicit codec indices for `TypeDef` and `TypeDefPrimitive` enums [(#127)](https://github.com/paritytech/scale-info/pull/127)

## [0.10.0] - 2021-07-29
### Added
- Add capture_docs attribute [(#118)](https://github.com/paritytech/scale-info/pull/118)
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "scale-info"
version = "0.10.0"
version = "0.11.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"

Expand Down
44 changes: 41 additions & 3 deletions src/ty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -238,23 +248,32 @@ where
#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, From, Debug, Encode)]
pub enum TypeDef<T: Form = MetaForm> {
/// A composite type (e.g. a struct or a tuple)
#[codec(index = 0)]
Composite(TypeDefComposite<T>),
/// A variant type (e.g. an enum)
#[codec(index = 1)]
Variant(TypeDefVariant<T>),
/// A sequence type with runtime known length.
#[codec(index = 2)]
Sequence(TypeDefSequence<T>),
/// An array type with compile-time known length.
#[codec(index = 3)]
Array(TypeDefArray<T>),
/// A tuple type.
#[codec(index = 4)]
Tuple(TypeDefTuple<T>),
/// A Range type.
Range(TypeDefRange<T>),
/// A Rust primitive type.
#[codec(index = 5)]
Primitive(TypeDefPrimitive),
/// A type using the [`Compact`] encoding
#[codec(index = 6)]
Compact(TypeDefCompact<T>),
/// A type representing a sequence of bits.
#[codec(index = 7)]
BitSequence(TypeDefBitSequence<T>),
/// A Range type.
#[codec(index = 8)]
Range(TypeDefRange<T>),
}

impl IntoPortable for TypeDef {
Expand All @@ -267,49 +286,68 @@ 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(),
}
}
}

/// 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,
}

Expand Down

0 comments on commit a028631

Please sign in to comment.