effect!() { /* proc-macro */ }Expand description
Do-notation over an async body, building an id_effect::Effect.
effect!({ body }) takes R from the expected type; effect!(|r: &Caps| { body }) fixes
R = Caps and binds r: &Caps. In the body, ~Cap reads a capability (&Arc<Cap>),
~expr runs a sub-effect over a part of R on the same fiber, widening its error (Never
to anything, else E: From<E2>), and ~(a, b, ..) joins up to 8 effects in parallel on
child fibers. ? on a Result fails the effect with its error. The body must be Send.
use id_effect::{Effect, Exit, Never, caps, effect, succeed};
struct Greeting(&'static str);
fn answer() -> Effect<u32> {
succeed(42)
}
fn hello() -> Effect<String, Never, caps!(Greeting)> {
effect!({ format!("{}:{}", ~Greeting.0, ~answer()) })
}
let out = hello().provide(Greeting("hi")).block_on();
assert!(matches!(out, Exit::Success(ref s) if s == "hi:42"));