Skip to content

Commit

Permalink
map_err2
Browse files Browse the repository at this point in the history
  • Loading branch information
dashed committed Oct 26, 2016
1 parent 57a618a commit 3f1998b
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,18 @@ impl<I: Input, T, E> ParseResult<I, T, E> {
}
}

#[inline]
pub fn map_err2<V, F>(self, f: F) -> ParseResult<I, T, V>
where F: FnOnce(E, &I) -> V {
match self {
ParseResult(i, Ok(t)) => ParseResult(i, Ok(t)),
ParseResult(i, Err(e)) => {
let err = f(e, &i);
ParseResult(i, Err(err))
},
}
}

/// Calls the function `f` with a reference of the contained data if the parser is in a success
/// state.
///
Expand Down

0 comments on commit 3f1998b

Please sign in to comment.