11 releases
new 0.5.3 | Mar 14, 2025 |
---|---|
0.5.2 | Apr 17, 2024 |
0.5.1 | Mar 29, 2024 |
0.4.2 | Feb 25, 2024 |
0.1.0 | Nov 21, 2023 |
#1800 in Rust patterns
83 downloads per month
72KB
974 lines
anony
Provides various constructs for anonymous types.
Macros
struct!
: Creates an instance of an anonymous struct.
use anony::r#struct;
let items = vec![1, 3, 5];
let x = r#struct! {
name: "discreaminant".to_owned(),
// Move the `items` variable into the struct
items,
};
assert_eq!(x.name, "discreaminant");
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!("discreaminant".to_owned(), items);
assert_eq!(x.0, "discreaminant");
assert_eq!(x.1, [1, 3, 5]);
join!
andjoin_cyclic!
: Join multiple futures. Requires thefuture
feature.
use anony::join;
assert_eq!(join!(async { 2 }, async { "123" }).await, (2, "123"));
try_join!
andtry_join_cyclic!
: Join multiple futures, short-circuiting on a "break" value. Requires thefuture
feature.
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/tree/master/examples/expansions
Features
serde
: DerivesSerialize
for anonymous structs and tuples. The serde crate must be included in your dependencies.future
: EnablesFuture
anonymous types, such asjoin!
.
Nightly
Add this to your dependencies:
anony = { git = "https://github.com/discreaminant2809/anony.git", branch = "nightly" }
Dependencies
~195–630KB
~15K SLoC