diff --git a/src/impls.rs b/src/impls.rs index ac7514b0..59bd9163 100644 --- a/src/impls.rs +++ b/src/impls.rs @@ -41,7 +41,6 @@ use crate::{ TypeDefArray, TypeDefCompact, TypeDefPrimitive, - TypeDefRange, TypeDefSequence, TypeDefTuple, TypeInfo, @@ -359,7 +358,14 @@ where { type Identity = Self; fn type_info() -> Type { - TypeDefRange::new::(false).into() + Type::builder() + .path(Path::prelude("Range")) + .type_params(type_params![Idx]) + .composite( + Fields::named() + .field(|f| f.name("start").ty::().type_name("Idx")) + .field(|f| f.name("end").ty::().type_name("Idx")), + ) } } @@ -369,7 +375,14 @@ where { type Identity = Self; fn type_info() -> Type { - TypeDefRange::new::(true).into() + Type::builder() + .path(Path::prelude("RangeInclusive")) + .type_params(type_params![Idx]) + .composite( + Fields::named() + .field(|f| f.name("start").ty::().type_name("Idx")) + .field(|f| f.name("end").ty::().type_name("Idx")), + ) } } diff --git a/src/ty/mod.rs b/src/ty/mod.rs index 165e0b5f..a0126b47 100644 --- a/src/ty/mod.rs +++ b/src/ty/mod.rs @@ -13,7 +13,6 @@ // limitations under the License. use crate::prelude::{ - fmt, vec, vec::Vec, }; @@ -115,7 +114,6 @@ impl_from_type_def_for_type!( TypeDefArray, TypeDefSequence, TypeDefTuple, - TypeDefRange, TypeDefCompact, TypeDefBitSequence, ); @@ -271,9 +269,6 @@ pub enum TypeDef { /// A type representing a sequence of bits. #[codec(index = 7)] BitSequence(TypeDefBitSequence), - /// A Range type. - #[codec(index = 8)] - Range(TypeDefRange), } impl IntoPortable for TypeDef { @@ -289,7 +284,6 @@ impl IntoPortable for TypeDef { 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(), } } } @@ -454,62 +448,6 @@ where } } -/// Type describing a [`Range`]. -#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] -#[cfg_attr( - feature = "serde", - serde(bound( - serialize = "T::Type: Serialize, T::String: Serialize", - deserialize = "T::Type: DeserializeOwned, T::String: DeserializeOwned", - )) -)] -#[cfg_attr(any(feature = "std", feature = "decode"), derive(scale::Decode))] -#[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Debug)] -pub struct TypeDefRange { - index_type: T::Type, - inclusive: bool, -} - -impl TypeDefRange { - /// Creates a new [`TypeDefRange`] for the supplied index type. Use the `inclusive` parameter to - /// distinguish between [`core::ops::Range`] and [`core::ops::RangeInclusive`] range types. - pub fn new(inclusive: bool) -> Self - where - Idx: PartialOrd + fmt::Debug + TypeInfo + 'static, - { - Self { - index_type: MetaType::new::(), - inclusive, - } - } -} - -impl TypeDefRange -where - T: Form, -{ - /// Returns the type of the index of the range. - pub fn index_type(&self) -> &T::Type { - &self.index_type - } - - /// Returns true if the range is inclusive as with [`core::ops::RangeInclusive`]. - pub fn inclusive(&self) -> bool { - self.inclusive - } -} - -impl IntoPortable for TypeDefRange { - type Output = TypeDefRange; - - fn into_portable(self, registry: &mut Registry) -> Self::Output { - TypeDefRange { - index_type: registry.register_type(&self.index_type), - inclusive: self.inclusive, - } - } -} - /// A type to refer to a sequence of elements of the same type. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(any(feature = "std", feature = "decode"), derive(scale::Decode))] diff --git a/test_suite/tests/json.rs b/test_suite/tests/json.rs index 6a50d9ba..53ac9fe2 100644 --- a/test_suite/tests/json.rs +++ b/test_suite/tests/json.rs @@ -394,7 +394,18 @@ fn test_ranges() { { "id": 1, "type": { - "def": { "range": { "index_type": 2, "inclusive": false} }, + "path": ["Range"], + "params": [ + { "name": "Idx", "type": 2 } + ], + "def": { + "composite": { + "fields": [ + { "name": "start", "type": 2, "typeName": "Idx" }, + { "name": "end", "type": 2, "typeName": "Idx" }, + ], + }, + } } }, { @@ -406,7 +417,18 @@ fn test_ranges() { { "id": 3, "type": { - "def": { "range": { "index_type": 4, "inclusive": true} }, + "path": ["RangeInclusive"], + "params": [ + { "name": "Idx", "type": 4 } + ], + "def": { + "composite": { + "fields": [ + { "name": "start", "type": 4, "typeName": "Idx" }, + { "name": "end", "type": 4, "typeName": "Idx" }, + ], + }, + } } }, {