Giter VIP home page Giter VIP logo

typeinfo's Introduction

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.

typeinfo's People

Contributors

aldanor avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

typeinfo's Issues

Examples use wrong attribute for importing macros

Just a minor issue, but the examples in the documentation is using

#[use_macro]
extern crate typeinfo;

instead of

#[macro_use]
extern crate typeinfo;

which will yield the following compilation error

error: macro undefined: 'def!'
 --> src/main.rs:6:1
  |
6 | def! {
  | ^^^

Update to use Macros 1.1

Macros 1.1 is going to be stabilizing in Rust 1.15 in February. It provides a more composable way to implement traits for data structures:

#[macro_use]
extern crate typeinfo_derive;

#[derive(Debug, TypeInfo)]
pub struct Color { r: u16, g: u16, b: u16 }

#[derive(Debug, TypeInfo)]
#[repr(packed)]
pub struct Palette {
    monochrome: bool,
    colors: [Color; 16],
}

Currently if I wanted to use typeinfo and another crate which has its own equivalent of the def! macro, there is no way for me to use both on the same struct.

Here is the RFC describing the Macros 1.1 feature and here is the tracking issue for stabilization.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.