move core result into core utils
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
5cb0a5f676
commit
c769fcc347
12 changed files with 2 additions and 3 deletions
15
src/core/utils/result/map_expect.rs
Normal file
15
src/core/utils/result/map_expect.rs
Normal file
|
@ -0,0 +1,15 @@
|
|||
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)) }
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue