Expand description
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]);
combine_futures!
andcombine_futures_cyclic!
: General-purpose future concurrency combinators. Requires thefuture
feature.
let mut s = String::new();
let fut = combine_futures! {
let ten = async { 10 } => continue {
s.write_fmt(format_args!("{ten}"));
ten
}
let zero = async { "0" } => continue s.push_str(zero),
};
assert_eq!(fut.await, (10, ()));
assert_eq!(s, "100");
let mut x = 2;
let fut = combine_futures_cyclic! {
move
match async { Some(1) } {
Some(x) if x % 2 == 0 => continue,
_ => break {
x += 1;
x
}
}
continue async {},
|_, _| -1
};
assert_eq!(fut.await, 3);
assert_eq!(x, 2);
§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 ascombine_futures!
.
§Nightly
Add this to your dependencies:
anony = { git = "https://github.com/discreaminant2809/anony.git", branch = "nightly" }
Macros§
- combine_
futures future
- Runs futures concurrently, where each one decides-on completion-whether to let others continue or short-circuit.
- combine_
futures_ cyclic future
- Runs futures concurrently, where each one decides-on completion-whether to let others continue or short-circuit. Uses a less deterministic polling order.
- join
Deprecated future
- Returns a future that “joins” multiple futures, allowing them to be completed concurrently. Its output is a tuple containing the outputs of the input futures.
- join_
cyclic Deprecated future
- Returns a future that “joins” multiple futures using a cyclic polling strategy, allowing them to be completed concurrently. Its output is a tuple containing the outputs of the input futures.
- struct
- Creates an instance of an anonymous struct.
- try_
join Deprecated future
- Returns a future that “joins” multiple futures, allowing them to be completed concurrently. May short-circuit.
- try_
join_ cyclic Deprecated future
- Returns a future that “joins” multiple futures using cycling polling strategy, allowing them to be completed concurrently. May short-circuit.
- tuple
- Creates an instance of an anonymous tuple.