pub trait Any:
TypeHash
+ Named
+ Any {
const ANY_TYPE_INFO: AnyTypeInfo = _;
}
Expand description
Derive for types which can be used inside of Rune.
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 is typically used in combination with declarative macros to register functions and macros, such as:
- [
#[rune::function]
] - [
#[rune::macro_]
]
[#[rune::function]
]: macro@crate::function
[#[rune::macro_]
]: crate::macro_
§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", so this trait is not object safe.
Implementations on Foreign Types§
impl Any for Option<Value>
impl Any for Result<Value, Value>
impl Any for Error
impl Any for ParseCharError
impl Any for Error
impl Any for ParseFloatError
impl Any for ParseIntError
impl Any for Utf8Error
impl Any for Error
Available on crate feature
std
only.Implementors§
impl Any for ControlFlow
impl Any for GeneratorState
impl Any for FromUtf8Error
Available on crate feature
alloc
only.