mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-11-16 05:36:50 +00:00
Add Result traits map_ref()/and_then_ref().
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
1 parent
ad9ddd91cd
commit
1cbcd3fc88
3 files changed
+40
-3
No files matched your search
@@ -0,0 +1,17 @@
|
||||
use super::Result;
|
||||
|
||||
pub trait AndThenRef<T, E> {
|
||||
fn and_then_ref<U, F>(self, op: F) -> Result<U, E>
|
||||
where
|
||||
F: FnOnce(&T) -> Result<U, E>;
|
||||
}
|
||||
|
||||
impl<T, E> AndThenRef<T, E> for Result<T, E> {
|
||||
#[inline]
|
||||
fn and_then_ref<U, F>(self, op: F) -> Result<U, E>
|
||||
where
|
||||
F: FnOnce(&T) -> Result<U, E>,
|
||||
{
|
||||
self.and_then(|t| op(&t))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
use super::Result;
|
||||
|
||||
pub trait MapRef<T, E> {
|
||||
fn map_ref<U, F>(self, op: F) -> Result<U, E>
|
||||
where
|
||||
F: FnOnce(&T) -> U;
|
||||
}
|
||||
|
||||
impl<T, E> MapRef<T, E> for Result<T, E> {
|
||||
#[inline]
|
||||
fn map_ref<U, F>(self, op: F) -> Result<U, E>
|
||||
where
|
||||
F: FnOnce(&T) -> U,
|
||||
{
|
||||
self.map(|t| op(&t))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user