diff --git a/crates/rune/src/any.rs b/crates/rune/src/any.rs index 0ccbb8464..fce380a0a 100644 --- a/crates/rune/src/any.rs +++ b/crates/rune/src/any.rs @@ -56,26 +56,45 @@ use crate::hash::Hash; /// ``` pub use rune_macros::Any; -/// A trait which can be stored inside of an [AnyObj](crate::runtime::AnyObj). +/// Derive for types which can be used inside of Rune. /// -/// We use our own marker trait that must be explicitly derived to prevent other -/// VM native types (like strings) which also implement `std::any::Any` from -/// being stored as an `AnyObj`. +/// Rune only supports two types, *built-in* types [`String`] and *external* +/// types which derive `Any`. Before they can be used they must be registered in +/// [`Context::install`] through a [`Module`]. /// -/// This means, that only types which derive `Any` can be used inside of the VM: +/// [`AnyObj`]: crate::runtime::AnyObj +/// [`Context::install`]: crate::Context::install +/// [`Module`]: crate::Module +/// [`String`]: alloc::string::String +/// +/// # Examples /// /// ``` /// use rune::Any; /// /// #[derive(Any)] /// struct Npc { -/// name: String, +/// #[rune(get)] +/// health: u32, +/// } +/// +/// impl Npc { +/// #[rune::function(path = Self::new)] +/// fn new(health: u32) -> Self { +/// Self { +/// health +/// } +/// } +/// } +/// +/// fn install() -> Result { +/// let mut module = rune::Module::new()?; +/// module.ty::()?; +/// Ok(module) /// } /// ``` pub trait Any: Named + any::Any { /// The type hash of the type. - /// - /// TODO: make const field when `TypeId::of` is const. fn type_hash() -> Hash; }