metatype

Crates.iometatype
lib.rsmetatype
version0.2.1
sourcesrc
created_at2018-07-20 16:00:47.142054
updated_at2021-07-10 11:32:05.298843
descriptionHelper methods to determine whether a type is `TraitObject`, `Slice` or `Concrete`, and work with them respectively.
homepagehttps://github.com/alecmocatta/metatype
repositoryhttps://github.com/alecmocatta/metatype
max_upload_size
id75225
size28,558
Alec Mocatta (alecmocatta)

documentation

https://docs.rs/metatype/0.2.1

README

metatype

Crates.io MIT / Apache 2.0 licensed Build Status

📖 Docs | 💬 Chat

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

Examples

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

let a: Box<usize> = Box::new(123);
assert_eq!(Type::meta_type(&*a), MetaType::Concrete);
let a: Box<dyn any::Any> = a;
assert_eq!(Type::meta_type(&*a), MetaType::TraitObject);

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

let a: Box<dyn any::Any> = 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.

Commit count: 39

cargo fmt