Comments (5)
anyhow!
handles the conversion.
use anyhow::anyhow;
fn main() {
let e: Box<dyn std::error::Error + Send + Sync> = unimplemented!();
let e = anyhow!(e);
}
from anyhow.
It could be shorter with map_err
instead of explicit match, eg something like:
something_returning_boxed_error().map_err(|e| anyhow!(e))?
This would be even slightly more ergonomic if it existed as a function/constructor/method, eg:
something_returning_boxed_error().map_err(Anyhow::from_boxed)?
But as long as Rust doesn't allow implementing impl From<Box<std::error::Error + Send + Sync>> for Anyhow
, this is probably the best that can be done :-(.
from anyhow.
Reading the docs, doesn't this stringify the error? Won't it lose all the source
chain, type information and such?
I'd hope it could somehow convert the existing dyn Error
from 2-words trait object to the internal 1-word trait object. Or is it not possible?
from anyhow.
Oh, I'm reading through the source code and it seems to be preserving it somehow. Would you mind if I send a PR making such usage clearer in the docs? Also, link from the Error
type to the macro would make it little bit easier to find.
from anyhow.
Perhaps I'm missing something but anyhow! isn't very easy to use with ?
.
fn main() -> anyhow::Result<()>{
something_returning_boxed_error()?;
}
is a bit awkward - I mean:
fn main() -> anyhow::Result<()>{
match something_returning_boxed_error(){
Ok(v) => Ok(v),
Err(e) => Err(anyhow!(e))
}?
}
from anyhow.
Related Issues (20)
- Nightly feature wrongly enabled on stable toolchain HOT 3
- Should `anyhow::Error::chain` return `dyn Error + Send + Sync` HOT 2
- Customize backtrace logic?
- `anyhow!(e)` doesn't preserve `source` for `&Error` HOT 1
- A way to disable anyhow stacktraces (without disabling stacktraces from other crates) HOT 2
- Default Ok-type to `()` in `anyhow::Result` typedef HOT 2
- Updating from version 1.0.76 breaks backtraces HOT 2
- Make backtrace support optional HOT 10
- Possible performance regression on Windows HOT 5
- as_ref() type must be known at this point
- Depending on `CARGO_ENCODED_RUSTFLAGS` may produce stale builds HOT 1
- rust-analyzer nightly throws needless_return warning on bail! HOT 2
- Implement Context for Error
- Question regarding stacktrace
- anyhow::Error to Box<dyn Error> isn't compatible with other libraries HOT 2
- Are you open to de-duplicating the build.rs build probe code? HOT 7
- `anyhow::ensure!` doesn't work with custom error type HOT 1
- Short backtrace HOT 2
- Feature suggestion: ensure_some!() for unwrapping options HOT 3
- Cannot compile when using `ensure!` HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from anyhow.