1
0
Fork 0
mirror of https://forgejo.ellis.link/continuwuation/continuwuity.git synced 2025-07-28 10:48:30 +00:00
continuwuity/src/core/utils/result/map_expect.rs
Jason Volk 3fbd74310f impl transposed form of MapExpect
Signed-off-by: Jason Volk <jason@zemos.net>
2024-12-01 10:51:04 +00:00

20 lines
645 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)) }
}
impl<'a, T, E: Debug> MapExpect<'a, Result<T, E>> for Result<Option<T>, E> {
#[inline]
fn map_expect(self, msg: &'a str) -> Result<T, E> { self.map(|result| result.expect(msg)) }
}