1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#[macro_use]
extern crate log;

/// convert a `Result<T,E>` into `Option<T>`, dropping the error E
///
/// The implementation is currently identical to `std::result::Result::ok()` but
/// could be used in the future to panic or log a warning.
pub trait CrossbeamOk<T> {
    fn cb_ok(self) -> Option<T>;
}

impl<T, E> CrossbeamOk<T> for std::result::Result<T, channellib::SendError<E>> {
    fn cb_ok(self) -> Option<T> {
        match self {
            Ok(val) => Some(val),
            Err(e) => {
                warn!("ignoring {}", e);
                None
            }
        }
    }
}

#[cfg(test)]
mod tests {
    #[test]
    fn it_works() {
        use crate::CrossbeamOk;
        let (tx, _rx) = crossbeam_channel::unbounded();
        tx.send(123u8).cb_ok();
    }
}