Skip to content

Commit

Permalink
First draft at extending option
Browse files Browse the repository at this point in the history
  • Loading branch information
dgrnbrg committed May 30, 2017
1 parent 62627ed commit eb159ad
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/error_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,17 @@ macro_rules! error_chain_processed {
}
}

impl<T, E> $result_ext_name<T, E> for ::std::option::Option<T> where E: ::std::error::Error + Send + 'static {
fn chain_err<F, EK>(self, callback: F) -> ::std::result::Result<T, $error_name>
where F: FnOnce() -> EK,
EK: Into<$error_kind_name> {
self.ok_or_else(move || {
let state = $crate::State::default();
$crate::ChainedError::new(callback().into(), state)
})
}
}


};
}
Expand Down

0 comments on commit eb159ad

Please sign in to comment.