Crate rtti [−] [src]
Run-time type information trait. Use crate rtti-derive to implement.
very early, probably best to stay away for now
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::rtti()); }
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::Unknown")] ignored: UnsupportedForeignType, } fn main() { println!("{:?}", Attributed::rtti()); }
When implementing RTTI for a generic type, make sure generic parameters implement RTTI:
#[derive(RTTI)] struct Generic<T> where T: RTTI { test: T, stuff: Simple, } fn main() { println!("{:?}", Generic::<u64>::rtti()); }
Structs
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). |
Enums
Type |
A type. |
Visibility |
Visibility of a type or struct member. |
Traits
RTTI |
Provides run-time type information. |