Value from Type -Macros

Latest Version Rust Documentation

Procedural macro attribute to match structure types with an enum variant.

This macro can be applied on a module to make a connection between each defined struct and a newly created enum type. This enum is built into the same module as the macro is invocated upon. The macro will also implement valuefromtype_traits::FromType on the enum for each struct (within the module) as generic argument.

Examples

```rust

![feature(proc_macro)]

extern crate valuefromtypemacros; extern crate valuefromtypetraits;

// Attribute macro must be imported through a use statement. use valuefromtypemacros::valuefromtype; // Implemented trait on EnumName use valuefromtypetraits::IntoEnum;

mod temp { // The parameter indicates the enum identifier. #![valuefromtype(EnumName)]

#[derive(Debug)]
pub struct X();

// Explicit import for sake of example. use self::temp::{EnumName, X}; // use self::temp::*;

fn main() { asserteq!(EnumName::X, X::intoenum()); } ```