10 releases (4 breaking)

0.5.2 Apr 17, 2024
0.5.1 Mar 29, 2024
0.4.2 Feb 25, 2024
0.4.1 Jan 22, 2024
0.1.0 Nov 21, 2023

#10 in #anonymous

Download history 13/week @ 2024-01-08 8/week @ 2024-01-15 10/week @ 2024-01-22 119/week @ 2024-02-19 44/week @ 2024-02-26 5/week @ 2024-03-04 4/week @ 2024-03-11 177/week @ 2024-03-18 123/week @ 2024-03-25 26/week @ 2024-04-01 2/week @ 2024-04-08 153/week @ 2024-04-15

306 downloads per month

MIT/Apache

67KB
974 lines

Provides various anonymous type constructs

Macros

  • struct!: creates an instance of an anonymous struct.
use anony::r#struct;

let items = vec![1, 3, 5];

let x = r#struct! {
    color: "Red".to_owned(),
    // move the `items` variable to the struct
    items
};

assert_eq!(x.color, "Red");
assert_eq!(x.items, [1, 3, 5]);
  • tuple!: creates an instance of an anonymous tuple.
use anony::tuple;

let items = vec![1, 3, 5];

let x = tuple!("Red".to_owned(), items);

assert_eq!(x.0, "Red");
assert_eq!(x.1, [1, 3, 5]);
use anony::join;

assert_eq!(join!(async { 2 }, async { "123" }).await, (2, "123"));
use anony::try_join;

assert_eq!(try_join!(async { Some(2) }, async { Some("123") }).await, Some((2, "123")));
assert_eq!(try_join!(async { Some(2) }, async { None::<i32> }).await, None);

Example Macro Expansions

https://github.com/discreaminant2809/anony/blob/master/examples/expansions.rs

Features

  • serde: derives Serialize for anonymous structs and tuples. serde crate must exist in your crate.
  • future: enables Future anonymous types, such as join!.

Disclaimer

All macros in this crate are 100% hygienic.

Dependencies

~300–750KB
~18K SLoC