diff --git a/src/module/mod.rs b/src/module/mod.rs index 34c2887b..976a554b 100644 --- a/src/module/mod.rs +++ b/src/module/mod.rs @@ -417,20 +417,68 @@ impl Module { } /// Map a custom type to a friendly display name. + /// + /// # Example + /// + /// ``` + /// # use rhai::Module; + /// #[derive(Clone)] + /// struct TestStruct {} + /// + /// let name = std::any::type_name::of::()); + /// + /// let mut module = Module::new(); + /// + /// module.set_custom_type("MyType"); + /// + /// assert_eq!(module.get_custom_type(name, Some("MyType")); + /// ``` #[inline(always)] - pub fn set_custom_type(&mut self, name: &str) { - self.custom_types.add_type::(name) + pub fn set_custom_type(&mut self, name: &str) -> &mut Self { + self.custom_types.add_type::(name); + self } /// Map a custom type to a friendly display name. + /// + /// ``` + /// # use rhai::Module; + /// #[derive(Clone)] + /// struct TestStruct {} + /// + /// let name = std::any::type_name::of::()); + /// + /// let mut module = Module::new(); + /// + /// module.set_custom_type_raw(name, "MyType"); + /// + /// assert_eq!(module.get_custom_type(name, Some("MyType")); + /// ``` #[inline(always)] pub fn set_custom_type_raw( &mut self, type_name: impl Into, name: impl Into, - ) { - self.custom_types.add(type_name, name) + ) -> &mut Self { + self.custom_types.add(type_name, name); + self } /// Get the display name of a registered custom type. + /// + /// # Example + /// + /// ``` + /// # use rhai::Module; + /// #[derive(Clone)] + /// struct TestStruct {} + /// + /// let name = std::any::type_name::of::()); + /// + /// let mut module = Module::new(); + /// + /// module.set_custom_type("MyType"); + /// + /// assert_eq!(module.get_custom_type(name, Some("MyType")); + /// ``` #[inline(always)] pub fn get_custom_type(&self, key: &str) -> Option<&str> { self.custom_types.get(key)