#early #traits #information #run-time #macro #rtti-derive

deprecated rtti

[very early WIP] Run-time type information trait. Use crate rtti-derive to implement.

5 releases (3 breaking)

Uses old Rust 2015

0.4.0 Mar 18, 2018
0.3.2 Feb 26, 2018
0.2.0 Feb 22, 2018
0.1.0 Feb 21, 2018

#35 in #early

MIT license

10KB
202 lines

RTTI-derive

Procedural macro to derive RTTI trait. See crate rtti.

very early, probably best to stay away for now

Documentation.


lib.rs:

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());
}

No runtime deps