Expand description
Run-time type information trait. Use crate rtti-derive
to implement.
To include RTTI, use:
#[macro_use]
extern crate rtti_derive;
extern crate rtti;
use rtti::RTTI;
You can then implement rtti()
for a custom type:
#[derive(RTTI)]
struct Simple {
x: u32,
pub y: ::std::sync::Arc<u32>,
pub(crate) z: Vec<f64>
}
fn main() {
println!("{:?}", Simple::ctti());
}
You can ignore fields or add hints using the ignore and hint attributes:
struct UnsupportedForeignType ();
#[derive(RTTI)]
struct Attributed {
#[rtti(hint = "foo")]
#[rtti(hint = "bar")]
pub foobard: ::std::sync::Arc<u32>,
#[rtti(ignore)]
#[rtti(hint = "sets type to Type::Ignored")]
ignored: UnsupportedForeignType,
}
fn main() {
println!("{:?}", Attributed::ctti());
}
When implementing RTTI for a generic type, make sure generic parameters implement RTTI:
#[derive(RTTI)]
struct Generic<T> where T: RTTI {
test: T,
stuff: i32,
}
fn main() {
println!("{:?}", Generic::<u64>::ctti());
}
Structs§
- Enum
- An enum.
- Field
- Field of a struct or tuple struct.
- Opaque
- An opaque type.
- Primitive
- An primitive type.
- Struct
- A struct (with named members).
- Tuple
- A tuple struct (unnamed members).
- Variant
- Variant of an enum.
Enums§
- Type
- A type.
- Visibility
- Visibility of a type or struct member.
Traits§
- RTTI
- Provides run-time type information.