pub trait Any:
TypeHash
+ Named
+ Any {
const ANY_TYPE_INFO: AnyTypeInfo = _;
}Expand description
The trait implemented for types which can be used inside of Rune.
This can only be implemented correctly through the Any derive.
Implementing it manually is not supported.
Rune only supports two types, built-in types like i64 and external
types which derive Any. Before they can be used they must be registered in
Context::install through a Module.
This is typically used in combination with declarative macros to register
functions and macros, such as rune::function.
§Examples
use rune::Any;
#[derive(Any)]
struct Npc {
#[rune(get)]
health: u32,
}
impl Npc {
/// Construct a new NPC.
#[rune::function(path = Self::new)]
fn new(health: u32) -> Self {
Self {
health
}
}
/// Damage the NPC with the given `amount`.
#[rune::function]
fn damage(&mut self, amount: u32) {
self.health -= amount;
}
}
fn install() -> Result<rune::Module, rune::ContextError> {
let mut module = rune::Module::new();
module.ty::<Npc>()?;
module.function_meta(Npc::new)?;
module.function_meta(Npc::damage)?;
Ok(module)
}Provided Associated Constants§
Sourceconst ANY_TYPE_INFO: AnyTypeInfo = _
const ANY_TYPE_INFO: AnyTypeInfo = _
The compile-time type information know for the type.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
impl Any for Error
Available on crate feature
std only.impl Any for Error
Available on crate feature
anyhow only.