metatype

Crates.io MIT / Apache 2.0 licensed Build Status

Docs

Helper methods to determine whether a type is TraitObject, Slice or Concrete, and work with them respectively.

Examples

```rust asserteq!(usize::METATYPE, MetaType::Concrete); asserteq!(any::Any::METATYPE, MetaType::TraitObject); assert_eq!(<[u8]>::METATYPE, MetaType::Slice);

let a: Box = Box::new(123); asserteq!(Type::metatype(&a), MetaType::Concrete); let a: Box = a; assert_eq!(Type::meta_type(&a), MetaType::TraitObject);

let a = [123,456]; asserteq!(Type::metatype(&a), MetaType::Concrete); let a: &[i32] = &a; asserteq!(Type::metatype(a), MetaType::Slice);

let a: Box = Box::new(123); let meta: TraitObject = type_coerce(Type::meta(&*a)); println!("vtable: {:?}", meta.vtable); ```

Note

This currently requires Rust nightly for the raw, specialization and arbitrary_self_types features.

License

Licensed under either of

at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.