typeinfo

Crates.iotypeinfo
lib.rstypeinfo
version0.1.1
sourcesrc
created_at2016-02-02 22:47:24.597345
updated_at2016-02-02 22:47:24.597345
descriptionRuntime type information for POD types.
homepagehttps://github.com/aldanor/typeinfo
repositoryhttps://github.com/aldanor/typeinfo
max_upload_size
id4065
size30,677
Ivan Smirnov (aldanor)

documentation

https://ivansmirnov.io/typeinfo

README

typeinfo

Build Status Build Status

Documentation

The typeinfo crate provides access to type information for POD (plain old data) types at runtime.

Examples

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)

License

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.

Commit count: 40

cargo fmt