Fix 'IntoOutcome' implementations for 'Option' and 'Result'.

Fixes #334.
This commit is contained in:
Sergio Benitez 2017-07-04 14:05:16 -07:00
parent 85051eae49
commit 6df5564983
3 changed files with 20 additions and 8 deletions

View File

@ -23,7 +23,10 @@ impl<'a, S, E> IntoOutcome<S, (Status, E), Data> for Result<S, E> {
#[inline]
fn or_forward(self, data: Data) -> Outcome<S, E> {
Forward(data)
match self {
Ok(val) => Success(val),
Err(_) => Forward(data)
}
}
}

View File

@ -125,14 +125,20 @@ impl<S, E, F> IntoOutcome<S, E, F> for Option<S> {
type Failure = E;
type Forward = F;
#[inline(always)]
fn into_outcome(self, val: E) -> Outcome<S, E, F> {
Failure(val)
#[inline]
fn into_outcome(self, failure: E) -> Outcome<S, E, F> {
match self {
Some(val) => Success(val),
None => Failure(failure)
}
}
#[inline(always)]
fn or_forward(self, val: F) -> Outcome<S, E, F> {
Forward(val)
#[inline]
fn or_forward(self, forward: F) -> Outcome<S, E, F> {
match self {
Some(val) => Success(val),
None => Forward(forward)
}
}
}

View File

@ -26,7 +26,10 @@ impl<S, E> IntoOutcome<S, (Status, E), ()> for Result<S, E> {
#[inline]
fn or_forward(self, _: ()) -> Outcome<S, E> {
Forward(())
match self {
Ok(val) => Success(val),
Err(_) => Forward(())
}
}
}