Crates.io | typeinfo |
lib.rs | typeinfo |
version | 0.1.1 |
source | src |
created_at | 2016-02-02 22:47:24.597345 |
updated_at | 2016-02-02 22:47:24.597345 |
description | Runtime type information for POD types. |
homepage | https://github.com/aldanor/typeinfo |
repository | https://github.com/aldanor/typeinfo |
max_upload_size | |
id | 4065 |
size | 30,677 |
The typeinfo
crate provides access to type information for POD (plain old data)
types at runtime.
Defining reflectable struct types only requires wrapping the struct definition in
the def!
macro:
#[use_macro]
extern crate typeinfo;
use typeinfo::TypeInfo;
def! {
#[derive(Debug)]
pub struct Color { r: u16, g: u16, b: u16, }
#[derive(Debug)]
#[repr(packed)]
pub struct Palette {
monochrome: bool,
colors: [Color; 16]
}
}
fn main() {
println!("{:#?}", Palette::type_info());
}
Output (whitespace formatted):
Compound([
Field { ty: Bool, name: "monochrome", offset: 0 },
Field {
ty: Array(
Compound([
Field { ty: UInt16, name: "r", offset: 0 },
Field { ty: UInt16, name: "g", offset: 2 },
Field { ty: UInt16, name: "b", offset: 4 }
], 6),
16),
name: "colors",
offset: 1
}
], 97)
typeinfo
is primarily distributed under the terms of both the MIT license and
the Apache License (Version 2.0), with portions covered by various BSD-like
licenses.
See LICENSE-APACHE, and LICENSE-MIT for details.