diff --git a/src/module/mod.rs b/src/module/mod.rs index 143be2a5..b348058f 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -586,10 +586,10 @@ impl Module { /// /// assert_eq!(module.get_custom_type(name), Some("MyType")); /// ``` - #[inline(always)] + #[inline] #[must_use] pub fn get_custom_type(&self, key: &str) -> Option<&str> { - self.custom_types.get(key) + self.custom_types.get(key).map(|t| t.display_name.as_str()) } /// Returns `true` if this [`Module`] contains no items. diff --git a/src/types/custom_types.rs b/src/types/custom_types.rs index 4331d545..b0cb8bfd 100644 --- a/src/types/custom_types.rs +++ b/src/types/custom_types.rs @@ -3,14 +3,18 @@ use crate::Identifier; use std::{any::type_name, collections::BTreeMap, fmt}; -/// _(internals)_ A custom type. +/// _(internals)_ Information for a custom type. /// Exported under the `internals` feature only. -pub type CustomType = Identifier; +#[derive(Debug, Eq, PartialEq, Clone, Hash, Default)] +pub struct CustomTypeInfo { + /// Friendly display name of the custom type. + pub display_name: Identifier, +} /// _(internals)_ A collection of custom types. /// Exported under the `internals` feature only. #[derive(Clone, Hash, Default)] -pub struct CustomTypesCollection(BTreeMap); +pub struct CustomTypesCollection(BTreeMap); impl fmt::Debug for CustomTypesCollection { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -33,21 +37,31 @@ impl CustomTypesCollection { /// Register a custom type. #[inline(always)] pub fn add(&mut self, type_name: impl Into, name: impl Into) { - self.add_raw(type_name, name.into()); + self.add_raw( + type_name, + CustomTypeInfo { + display_name: name.into(), + }, + ); } /// Register a custom type. #[inline(always)] pub fn add_type(&mut self, name: &str) { - self.add_raw(type_name::(), name.into()); + self.add_raw( + type_name::(), + CustomTypeInfo { + display_name: name.into(), + }, + ); } /// Register a custom type. #[inline(always)] - pub fn add_raw(&mut self, type_name: impl Into, custom_type: CustomType) { + pub fn add_raw(&mut self, type_name: impl Into, custom_type: CustomTypeInfo) { self.0.insert(type_name.into(), custom_type); } /// Find a custom type. #[inline(always)] - pub fn get(&self, key: &str) -> Option<&str> { - self.0.get(key).map(CustomType::as_str) + pub fn get(&self, key: &str) -> Option<&CustomTypeInfo> { + self.0.get(key) } } diff --git a/src/types/mod.rs b/src/types/mod.rs index 6fad549e..6e2843e2 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -9,7 +9,7 @@ pub mod interner; pub mod parse_error; pub mod scope; -pub use custom_types::{CustomType, CustomTypesCollection}; +pub use custom_types::{CustomTypeInfo, CustomTypesCollection}; pub use dynamic::Dynamic; #[cfg(not(feature = "no_std"))] pub use dynamic::Instant;