From 5dc4b8330b68aad315126e76deae6274b5d952b8 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 28 Mar 2023 19:41:16 +0300 Subject: [PATCH 1/7] portable: Expose types as mutable from the PortableRegistry Signed-off-by: Alexandru Vasile --- src/portable.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/portable.rs b/src/portable.rs index 74aae9e0..97fc7bdb 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -71,6 +71,11 @@ impl PortableRegistry { self.types.get(id as usize).map(|ty| ty.ty()) } + /// Returns the mutable type definition for the given identifier, `None` if no type found for that ID. + pub fn resolve_mut(&mut self, id: u32) -> Option<&mut Type> { + self.types.get_mut(id as usize).map(|ty| ty.ty_mut()) + } + /// Returns all types with their associated identifiers. pub fn types(&self) -> &[PortableType] { &self.types @@ -256,6 +261,11 @@ impl PortableType { pub fn ty(&self) -> &Type { &self.ty } + + /// Returns the mutable type of the [`PortableType`]. + pub fn ty_mut(&mut self) -> &mut Type { + &mut self.ty + } } /// Construct a [`PortableRegistry`]. From a354dd04edeb906703d42b6d6a16b70999e56a18 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 8 Mar 2023 17:39:47 +0200 Subject: [PATCH 2/7] ty: Make type fields public Signed-off-by: Alexandru Vasile --- src/portable.rs | 13 ++----------- src/ty/composite.rs | 2 +- src/ty/fields.rs | 8 ++++---- src/ty/mod.rs | 26 +++++++++++++------------- src/ty/variant.rs | 2 +- 5 files changed, 21 insertions(+), 30 deletions(-) diff --git a/src/portable.rs b/src/portable.rs index 97fc7bdb..54f18fec 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -46,7 +46,8 @@ use scale::Encode; #[cfg_attr(any(feature = "std", feature = "decode"), derive(scale::Decode))] #[derive(Clone, Debug, PartialEq, Eq, Encode)] pub struct PortableRegistry { - types: Vec, + /// The types contained by the [`PortableRegistry`]. + pub types: Vec, } impl From for PortableRegistry { @@ -71,11 +72,6 @@ impl PortableRegistry { self.types.get(id as usize).map(|ty| ty.ty()) } - /// Returns the mutable type definition for the given identifier, `None` if no type found for that ID. - pub fn resolve_mut(&mut self, id: u32) -> Option<&mut Type> { - self.types.get_mut(id as usize).map(|ty| ty.ty_mut()) - } - /// Returns all types with their associated identifiers. pub fn types(&self) -> &[PortableType] { &self.types @@ -261,11 +257,6 @@ impl PortableType { pub fn ty(&self) -> &Type { &self.ty } - - /// Returns the mutable type of the [`PortableType`]. - pub fn ty_mut(&mut self) -> &mut Type { - &mut self.ty - } } /// Construct a [`PortableRegistry`]. diff --git a/src/ty/composite.rs b/src/ty/composite.rs index 26d8852a..8815966b 100644 --- a/src/ty/composite.rs +++ b/src/ty/composite.rs @@ -76,7 +76,7 @@ pub struct TypeDefComposite { feature = "serde", serde(skip_serializing_if = "Vec::is_empty", default) )] - pub(crate) fields: Vec>, + pub fields: Vec>, } impl IntoPortable for TypeDefComposite { diff --git a/src/ty/fields.rs b/src/ty/fields.rs index 5d8d0029..7b71faeb 100644 --- a/src/ty/fields.rs +++ b/src/ty/fields.rs @@ -78,22 +78,22 @@ pub struct Field { feature = "serde", serde(skip_serializing_if = "Option::is_none", default) )] - pub(crate) name: Option, + pub name: Option, /// The type of the field. #[cfg_attr(feature = "serde", serde(rename = "type"))] - pub(crate) ty: T::Type, + pub ty: T::Type, /// The name of the type of the field as it appears in the source code. #[cfg_attr( feature = "serde", serde(skip_serializing_if = "Option::is_none", default) )] - pub(crate) type_name: Option, + pub type_name: Option, /// Documentation #[cfg_attr( feature = "serde", serde(skip_serializing_if = "Vec::is_empty", default) )] - pub(crate) docs: Vec, + pub docs: Vec, } impl IntoPortable for Field { diff --git a/src/ty/mod.rs b/src/ty/mod.rs index 56bf4c71..2f79a7d0 100644 --- a/src/ty/mod.rs +++ b/src/ty/mod.rs @@ -68,22 +68,22 @@ pub struct Type { feature = "serde", serde(skip_serializing_if = "Path::is_empty", default) )] - pub(crate) path: Path, + pub path: Path, /// The generic type parameters of the type in use. Empty for non generic types #[cfg_attr( feature = "serde", serde(rename = "params", skip_serializing_if = "Vec::is_empty", default) )] - pub(crate) type_params: Vec>, + pub type_params: Vec>, /// The actual type definition #[cfg_attr(feature = "serde", serde(rename = "def"))] - pub(crate) type_def: TypeDef, + pub type_def: TypeDef, /// Documentation #[cfg_attr( feature = "serde", serde(skip_serializing_if = "Vec::is_empty", default) )] - pub(crate) docs: Vec, + pub docs: Vec, } impl IntoPortable for Type { @@ -194,12 +194,12 @@ where #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, From, Debug, Encode)] pub struct TypeParameter { /// The name of the generic type parameter e.g. "T". - pub(crate) name: T::String, + pub name: T::String, /// The concrete type for the type parameter. /// /// `None` if the type parameter is skipped. #[cfg_attr(feature = "serde", serde(rename = "type"))] - pub(crate) ty: Option, + pub ty: Option, } impl IntoPortable for TypeParameter { @@ -400,10 +400,10 @@ pub enum TypeDefPrimitive { #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Debug)] pub struct TypeDefArray { /// The length of the array type. - pub(crate) len: u32, + pub len: u32, /// The element type of the array type. #[cfg_attr(feature = "serde", serde(rename = "type"))] - pub(crate) type_param: T::Type, + pub type_param: T::Type, } impl IntoPortable for TypeDefArray { @@ -452,7 +452,7 @@ where #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Debug)] pub struct TypeDefTuple { /// The types of the tuple fields. - pub(crate) fields: Vec, + pub fields: Vec, } impl IntoPortable for TypeDefTuple { @@ -514,7 +514,7 @@ where pub struct TypeDefSequence { /// The element type of the sequence type. #[cfg_attr(feature = "serde", serde(rename = "type"))] - pub(crate) type_param: T::Type, + pub type_param: T::Type, } impl IntoPortable for TypeDefSequence { @@ -564,7 +564,7 @@ where pub struct TypeDefCompact { /// The type wrapped in [`Compact`], i.e. the `T` in `Compact`. #[cfg_attr(feature = "serde", serde(rename = "type"))] - pub(crate) type_param: T::Type, + pub type_param: T::Type, } impl IntoPortable for TypeDefCompact { @@ -603,9 +603,9 @@ where #[derive(PartialEq, Eq, PartialOrd, Ord, Clone, Encode, Debug)] pub struct TypeDefBitSequence { /// The type implementing [`bitvec::store::BitStore`]. - pub(crate) bit_store_type: T::Type, + pub bit_store_type: T::Type, /// The type implementing [`bitvec::order::BitOrder`]. - pub(crate) bit_order_type: T::Type, + pub bit_order_type: T::Type, } impl IntoPortable for TypeDefBitSequence { diff --git a/src/ty/variant.rs b/src/ty/variant.rs index fb4944c2..b76b435b 100644 --- a/src/ty/variant.rs +++ b/src/ty/variant.rs @@ -88,7 +88,7 @@ pub struct TypeDefVariant { feature = "serde", serde(skip_serializing_if = "Vec::is_empty", default) )] - pub(crate) variants: Vec>, + pub variants: Vec>, } impl IntoPortable for TypeDefVariant { From f636cbcdae06077babaa729209f3ceabc64f8150 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Tue, 28 Mar 2023 20:12:20 +0300 Subject: [PATCH 3/7] portable: Make `PortableType` public Signed-off-by: Alexandru Vasile --- src/portable.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/portable.rs b/src/portable.rs index 54f18fec..255c2d83 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -237,9 +237,9 @@ impl PortableRegistry { #[derive(Clone, Debug, PartialEq, Eq, Encode)] pub struct PortableType { #[codec(compact)] - id: u32, + pub id: u32, #[cfg_attr(feature = "serde", serde(rename = "type"))] - ty: Type, + pub ty: Type, } impl PortableType { From 173adcd6115310c340eeb007e7165cdffd6bb156 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 29 Mar 2023 13:45:24 +0300 Subject: [PATCH 4/7] Deprecate getters Signed-off-by: Alexandru Vasile --- src/interner.rs | 6 +++++- src/portable.rs | 4 ++++ src/ty/composite.rs | 4 ++++ src/ty/fields.rs | 16 ++++++++++++++ src/ty/mod.rs | 52 +++++++++++++++++++++++++++++++++++++++++++++ src/ty/path.rs | 6 +++++- src/ty/variant.rs | 20 +++++++++++++++++ 7 files changed, 106 insertions(+), 2 deletions(-) diff --git a/src/interner.rs b/src/interner.rs index 65ae7d26..1d7b3d1c 100644 --- a/src/interner.rs +++ b/src/interner.rs @@ -49,13 +49,17 @@ use serde::{ pub struct UntrackedSymbol { /// The index to the symbol in the interner table. #[codec(compact)] - id: u32, + pub id: u32, #[cfg_attr(feature = "serde", serde(skip))] marker: PhantomData T>, } impl UntrackedSymbol { /// Returns the index to the symbol in the interner table. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn id(&self) -> u32 { self.id } diff --git a/src/portable.rs b/src/portable.rs index 255c2d83..29b83532 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -73,6 +73,10 @@ impl PortableRegistry { } /// Returns all types with their associated identifiers. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn types(&self) -> &[PortableType] { &self.types } diff --git a/src/ty/composite.rs b/src/ty/composite.rs index 8815966b..de18b503 100644 --- a/src/ty/composite.rs +++ b/src/ty/composite.rs @@ -109,6 +109,10 @@ where T: Form, { /// Returns the fields of the composite type. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn fields(&self) -> &[Field] { &self.fields } diff --git a/src/ty/fields.rs b/src/ty/fields.rs index 7b71faeb..9e944e79 100644 --- a/src/ty/fields.rs +++ b/src/ty/fields.rs @@ -141,11 +141,19 @@ where T: Form, { /// Returns the name of the field. None for unnamed fields. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn name(&self) -> Option<&T::String> { self.name.as_ref() } /// Returns the type of the field. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn ty(&self) -> &T::Type { &self.ty } @@ -155,11 +163,19 @@ where /// name are not specified, but in practice will be the name of any valid /// type for a field. This is intended for informational and diagnostic /// purposes only. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn type_name(&self) -> Option<&T::String> { self.type_name.as_ref() } /// Returns the documentation of the field. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn docs(&self) -> &[T::String] { &self.docs } diff --git a/src/ty/mod.rs b/src/ty/mod.rs index 2f79a7d0..08375ead 100644 --- a/src/ty/mod.rs +++ b/src/ty/mod.rs @@ -161,21 +161,37 @@ where T: Form, { /// Returns the path of the type + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn path(&self) -> &Path { &self.path } /// Returns the generic type parameters of the type + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn type_params(&self) -> &[TypeParameter] { &self.type_params } /// Returns the definition of the type + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn type_def(&self) -> &TypeDef { &self.type_def } /// Returns the documentation of the type + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn docs(&self) -> &[T::String] { &self.docs } @@ -240,11 +256,19 @@ where /// Get the type of the parameter. /// /// `None` if the parameter is skipped. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn ty(&self) -> Option<&T::Type> { self.ty.as_ref() } /// Get the name of the parameter. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn name(&self) -> &T::String { &self.name } @@ -428,11 +452,19 @@ where } /// Returns the length of the array type. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn len(&self) -> u32 { self.len } /// Returns the element type of the array type. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn type_param(&self) -> &T::Type { &self.type_param } @@ -502,6 +534,10 @@ where T: Form, { /// Returns the types of the tuple fields. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn fields(&self) -> &[T::Type] { &self.fields } @@ -552,6 +588,10 @@ where } /// Returns the element type of the sequence type. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn type_param(&self) -> &T::Type { &self.type_param } @@ -587,6 +627,10 @@ where } /// Returns the [`Compact`] wrapped type, i.e. the `T` in `Compact`. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn type_param(&self) -> &T::Type { &self.type_param } @@ -624,11 +668,19 @@ where T: Form, { /// Returns the type of the bit ordering of the [`::bitvec::vec::BitVec`]. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn bit_order_type(&self) -> &T::Type { &self.bit_order_type } /// Returns underlying type used to store the [`::bitvec::vec::BitVec`]. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn bit_store_type(&self) -> &T::Type { &self.bit_store_type } diff --git a/src/ty/path.rs b/src/ty/path.rs index 564f2a86..872a5774 100644 --- a/src/ty/path.rs +++ b/src/ty/path.rs @@ -59,7 +59,7 @@ use serde::{ #[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Clone, Encode)] pub struct Path { /// The segments of the namespace. - segments: Vec, + pub segments: Vec, } impl Default for Path @@ -158,6 +158,10 @@ where } /// Returns the segments of the Path + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn segments(&self) -> &[T::String] { &self.segments } diff --git a/src/ty/variant.rs b/src/ty/variant.rs index b76b435b..a7f72de4 100644 --- a/src/ty/variant.rs +++ b/src/ty/variant.rs @@ -121,6 +121,10 @@ where T: Form, { /// Returns the variants of a variant type + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn variants(&self) -> &[Variant] { &self.variants } @@ -212,21 +216,37 @@ where T: Form, { /// Returns the name of the variant. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn name(&self) -> &T::String { &self.name } /// Returns the fields of the struct variant. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn fields(&self) -> &[Field] { &self.fields } /// Returns the index of the variant. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn index(&self) -> u8 { self.index } /// Returns the documentation of the variant. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn docs(&self) -> &[T::String] { &self.docs } From 73cb1d2232f8a1b83e2568e1ff01be8f2abba6ee Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 29 Mar 2023 14:07:13 +0300 Subject: [PATCH 5/7] Adjust codebase to use inner fields Signed-off-by: Alexandru Vasile --- src/build.rs | 2 +- src/portable.rs | 34 +++++++++++++++------------------- src/registry.rs | 6 +++--- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/build.rs b/src/build.rs index 9cbecb54..75129e98 100644 --- a/src/build.rs +++ b/src/build.rs @@ -303,7 +303,7 @@ impl FieldsBuilder { impl FieldsBuilder { fn push_field(mut self, field: Field) -> Self { // filter out fields of PhantomData - if !field.ty().is_phantom() { + if !field.ty.is_phantom() { self.fields.push(field); } self diff --git a/src/portable.rs b/src/portable.rs index 29b83532..f54aa6f5 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -57,7 +57,7 @@ impl From for PortableRegistry { .types() .map(|(k, v)| { PortableType { - id: k.id(), + id: k.id, ty: v.clone(), } }) @@ -126,10 +126,10 @@ impl PortableRegistry { // Make sure any type params are also retained: for param in ty.ty.type_params.iter_mut() { - let Some(ty) = param.ty() else { + let Some(ty) = ¶m.ty else { continue }; - let new_id = retain_type(ty.id(), types, new_types, retained_mappings); + let new_id = retain_type(ty.id, types, new_types, retained_mappings); param.ty = Some(new_id).map(Into::into); } @@ -137,12 +137,8 @@ impl PortableRegistry { match &mut ty.ty.type_def { TypeDef::Composite(composite) => { for field in composite.fields.iter_mut() { - let new_id = retain_type( - field.ty.id(), - types, - new_types, - retained_mappings, - ); + let new_id = + retain_type(field.ty.id, types, new_types, retained_mappings); field.ty = new_id.into(); } } @@ -150,7 +146,7 @@ impl PortableRegistry { for var in variant.variants.iter_mut() { for field in var.fields.iter_mut() { let new_id = retain_type( - field.ty.id(), + field.ty.id, types, new_types, retained_mappings, @@ -161,7 +157,7 @@ impl PortableRegistry { } TypeDef::Sequence(sequence) => { let new_id = retain_type( - sequence.type_param.id(), + sequence.type_param.id, types, new_types, retained_mappings, @@ -170,7 +166,7 @@ impl PortableRegistry { } TypeDef::Array(array) => { let new_id = retain_type( - array.type_param.id(), + array.type_param.id, types, new_types, retained_mappings, @@ -180,14 +176,14 @@ impl PortableRegistry { TypeDef::Tuple(tuple) => { for ty in tuple.fields.iter_mut() { let new_id = - retain_type(ty.id(), types, new_types, retained_mappings); + retain_type(ty.id, types, new_types, retained_mappings); *ty = new_id.into(); } } TypeDef::Primitive(_) => (), TypeDef::Compact(compact) => { let new_id = retain_type( - compact.type_param().id(), + compact.type_param.id, types, new_types, retained_mappings, @@ -196,13 +192,13 @@ impl PortableRegistry { } TypeDef::BitSequence(bit_seq) => { let bit_store_id = retain_type( - bit_seq.bit_store_type().id(), + bit_seq.bit_store_type.id, types, new_types, retained_mappings, ); let bit_order_id = retain_type( - bit_seq.bit_order_type().id(), + bit_seq.bit_order_type.id, types, new_types, retained_mappings, @@ -283,7 +279,7 @@ impl PortableRegistryBuilder { /// /// If the type is already registered it will return the existing ID. pub fn register_type(&mut self, ty: Type) -> u32 { - self.types.intern_or_get(ty).1.into_untracked().id() + self.types.intern_or_get(ty).1.into_untracked().id } /// Returns the type id that would be assigned to a newly registered type. @@ -637,9 +633,9 @@ mod tests { let readonly: PortableRegistry = registry.into(); - assert_eq!(4, readonly.types().len()); + assert_eq!(4, readonly.types.len()); - for (expected, ty) in readonly.types().iter().enumerate() { + for (expected, ty) in readonly.types.iter().enumerate() { assert_eq!(expected as u32, ty.id()); } } diff --git a/src/registry.rs b/src/registry.rs index bda7993f..a5304b71 100644 --- a/src/registry.rs +++ b/src/registry.rs @@ -215,9 +215,9 @@ mod tests { let type_id = registry.register_type(&meta_type::()); let recursive = registry.types.get(&type_id).unwrap(); - if let TypeDef::Composite(composite) = recursive.type_def() { - for field in composite.fields() { - assert_eq!(*field.ty(), type_id) + if let TypeDef::Composite(composite) = &recursive.type_def { + for field in &composite.fields { + assert_eq!(field.ty, type_id) } } else { panic!("Should be a composite type definition") From 985776baf331f6608e1ce3e8322867481288727a Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 29 Mar 2023 18:05:48 +0300 Subject: [PATCH 6/7] portable: Deprecate PortableType id() and ty() Signed-off-by: Alexandru Vasile --- src/portable.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/portable.rs b/src/portable.rs index f54aa6f5..03b15234 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -249,11 +249,19 @@ impl PortableType { } /// Returns the index of the [`PortableType`]. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn id(&self) -> u32 { self.id } /// Returns the type of the [`PortableType`]. + #[deprecated( + since = "2.5.0", + note = "Prefer to access the fields directly; this getter will be removed in the next major version" + )] pub fn ty(&self) -> &Type { &self.ty } From b302b91e583779c1af92320c64d3529c03662506 Mon Sep 17 00:00:00 2001 From: Alexandru Vasile Date: Wed, 29 Mar 2023 19:41:21 +0300 Subject: [PATCH 7/7] portable: Don't use deprecated getters Signed-off-by: Alexandru Vasile --- src/portable.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/portable.rs b/src/portable.rs index 03b15234..ca0b51de 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -69,7 +69,7 @@ impl From for PortableRegistry { impl PortableRegistry { /// Returns the type definition for the given identifier, `None` if no type found for that ID. pub fn resolve(&self, id: u32) -> Option<&Type> { - self.types.get(id as usize).map(|ty| ty.ty()) + self.types.get(id as usize).map(|ty| &ty.ty) } /// Returns all types with their associated identifiers. @@ -644,7 +644,7 @@ mod tests { assert_eq!(4, readonly.types.len()); for (expected, ty) in readonly.types.iter().enumerate() { - assert_eq!(expected as u32, ty.id()); + assert_eq!(expected as u32, ty.id); } }