cristicbz / failchain Goto Github PK
View Code? Open in Web Editor NEWfailure + error-chain = ๐
License: Apache License 2.0
failure + error-chain = ๐
License: Apache License 2.0
It's real nice having result.chain_err(|| ...)
for your results but then when using code involving futures you end up having to go back to
future.map_err(|e| -> MyError {
let kind = ...;
e.context(kind).into()
})
In order to get around this, I made a variant of ResultExt
that works for futures (0.1 for now):
pub trait FutureExt<S, E: Fail>: Sized + Future<Item = S, Error = E> {
fn chain_inspect_err_fut<ErrorKindT: ChainErrorKind>(
self,
fn_in: impl FnOnce(&mut E) -> ErrorKindT + Send + Sync + 'static,
) -> MapErr<Self, Box<dyn FnOnce(E) -> ErrorKindT::Error + Send + Sync>> {
self.map_err(Box::new(|mut e| {
let kind = fn_in(&mut e);
e.context(kind).into()
}))
}
fn chain_err_fut<ErrorKindT: ChainErrorKind>(
self,
fn_in: impl FnOnce() -> ErrorKindT + Send + Sync + 'static,
) -> MapErr<Self, Box<dyn FnOnce(E) -> ErrorKindT::Error + Send + Sync>> {
self.chain_inspect_err_fut(|_| fn_in())
}
}
impl<S, E: Fail, F: Future<Item = S, Error = E>> FutureExt<S, E> for F {}
// used like:
client
.request(request)
.chain_err_fut(|| ErrorKind::OtherError("foo".to_owned()))
Some immediate issues:
Send + Sync + 'static
and need to enforce them, maybe some use cases don'timpl Fn
in traits.Is there any interest here? I'm using it and it seems handy. Maybe there's a better discussion to be had in failure
's ResultExt
which could have the same pattern?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.