continuwuity/src/core/utils/result/map_expect.rs
Jason Volk f191b4bad4 add map_expect for stream
Signed-off-by: Jason Volk <jason@zemos.net>
2024-11-03 14:50:28 +00:00

15 lines
461 B
Rust

use std::fmt::Debug;
use super::Result;
pub trait MapExpect<'a, T> {
/// Calls expect(msg) on the mapped Result value. This is similar to
/// map(Result::unwrap) but composes an expect call and message without
/// requiring a closure.
fn map_expect(self, msg: &'a str) -> T;
}
impl<'a, T, E: Debug> MapExpect<'a, Option<T>> for Option<Result<T, E>> {
#[inline]
fn map_expect(self, msg: &'a str) -> Option<T> { self.map(|result| result.expect(msg)) }
}