anon

Crates.ioanon
lib.rsanon
version0.1.0
sourcesrc
created_at2016-08-20 06:57:33.955158
updated_at2016-08-20 06:57:33.955158
descriptionAnonymous struct macro.
homepagehttps://github.com/ktakeda/anon
repositoryhttps://github.com/ktakeda/anon
max_upload_size
id6035
size2,167
(ktakeda)

documentation

https://github.com/ktakeda/anon

README

anon

anon!{} is a Rust macro which create anonymous structs, like C# anonymous types.

Usage

Add this to your Cargo.toml:

[dependencies]
anon = { git = "https://github.com/ktakeda/anon" }

and this to your crate root:

#[macro_use(anon)]
extern crate anon;

Examples

#[macro_use(anon)]
extern crate anon;

#[allow(non_camel_case_types)]
fn main() {
    let a = anon! { a: 10, b: 20 };
    assert_eq!(10, a.a);
    assert_eq!(20, a.b);
}

Anon can be used in closure:

#[macro_use(anon)]
extern crate anon;

#[allow(non_camel_case_types)]
fn main() {
    let y: Vec<_> = vec![1,2].into_iter().map(|x| {
        anon! { a: x, b: x*x } // create anonymous struct
    }).collect();
    assert_eq!(1, y[0].a);
    assert_eq!(2, y[1].a);
    assert_eq!(1, y[0].b);
    assert_eq!(4, y[1].b);
}

LICENSE

MIT.

Commit count: 8

cargo fmt