Macro ergo_sync::ch_try
[−]
[src]
macro_rules! ch_try { [$send:ident, $expr:expr, $action:expr] => { ... }; }
Handle an expression that could be Err
and send it over a channel if it is.
This is the same as the builtin try!
macro, except if the expression fails than the Err
is
sent on the $send
channel and the requested action is performed.
Suggested possible actions:
- continue
- return
- break
- some expression that evaluates to a "default value" for that context.
Examples
#[macro_use] extern crate ergo_sync; use ergo_sync::*; let (send_err, recv_err) = ch::unbounded(); let items = &[Ok("this is alright"), Err("not ok"), Err("still not okay")]; for item in items.iter() { let v = ch_try!(send_err, *item, continue); println!("got: {}", v); } drop(send_err); let errs: Vec<_> = recv_err.iter().collect(); assert_eq!(vec!["not ok", "still not okay"], errs);