mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2025-07-28 18:58:30 +00:00
16 lines
443 B
Rust
16 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)) }
|
||
|
}
|