anon 0.1.0

Anonymous struct macro.
Documentation
  • Coverage
  • 0%
    0 out of 2 items documented0 out of 0 items with examples
  • Size
  • Source code size: 2.31 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.03 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 9s Average build duration of successful builds.
  • all releases: 9s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Homepage
  • Documentation
  • ktakeda/anon
    3 1 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ktakeda

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.