continuwuity/src/core/result/map_expect.rs
Jason Volk 2709995f84 add MapExpect to Result
add DebugInspect to Result

move Result typedef into unit

Signed-off-by: Jason Volk <jason@zemos.net>
2024-10-25 00:15:01 -04:00

15 lines
443 B
Rust

use std::fmt::Debug;
use super::Result;
pub trait MapExpect<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: &str) -> Option<T>;
}
impl<T, E: Debug> MapExpect<T> for Option<Result<T, E>> {
#[inline]
fn map_expect(self, msg: &str) -> Option<T> { self.map(|result| result.expect(msg)) }
}