Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/alecmocatta/metatype
Helper methods to work with Rust types.
https://github.com/alecmocatta/metatype
rust slice trait-object types vtable
Last synced: about 1 month ago
JSON representation
Helper methods to work with Rust types.
- Host: GitHub
- URL: https://github.com/alecmocatta/metatype
- Owner: alecmocatta
- License: apache-2.0
- Created: 2018-07-20T15:37:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-10T11:34:30.000Z (over 3 years ago)
- Last Synced: 2024-10-07T11:20:56.634Z (about 1 month ago)
- Topics: rust, slice, trait-object, types, vtable
- Language: Rust
- Homepage:
- Size: 48.8 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE-APACHE.txt
Awesome Lists containing this project
README
# metatype
[![Crates.io](https://img.shields.io/crates/v/metatype.svg?maxAge=86400)](https://crates.io/crates/metatype)
[![MIT / Apache 2.0 licensed](https://img.shields.io/crates/l/metatype.svg?maxAge=2592000)](#License)
[![Build Status](https://dev.azure.com/alecmocatta/metatype/_apis/build/status/tests?branchName=master)](https://dev.azure.com/alecmocatta/metatype/_build?definitionId=7)[📖 Docs](https://docs.rs/metatype/0.2) | [💬 Chat](https://constellation.zulipchat.com/#narrow/stream/213236-subprojects)
Helper methods to determine whether a type is `TraitObject`, `Slice` or `Concrete`, and work with them respectively.
## Examples
```rust
assert_eq!(usize::METATYPE, MetaType::Concrete);
assert_eq!(any::Any::METATYPE, MetaType::TraitObject);
assert_eq!(<[u8]>::METATYPE, MetaType::Slice);let a: Box = Box::new(123);
assert_eq!(Type::meta_type(&*a), MetaType::Concrete);
let a: Box = 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 = Box::new(123);
let meta: TraitObject = type_coerce(Type::meta(&*a));
println!("vtable: {:?}", meta.vtable);
```## Note
This currently requires Rust nightly for the `ptr_metadata`, `specialization` and `arbitrary_self_types` features.
## License
Licensed under either of
* Apache License, Version 2.0, ([LICENSE-APACHE.txt](LICENSE-APACHE.txt) or http://www.apache.org/licenses/LICENSE-2.0)
* MIT license ([LICENSE-MIT.txt](LICENSE-MIT.txt) or http://opensource.org/licenses/MIT)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.