Replies: 4 comments
-
|
I believe you can use #[derive(Debug, Snafu)]
#[snafu(source(from(InnerError, Box::new)))]
pub struct Error(Box<InnerError>); |
Beta Was this translation helpful? Give feedback.
-
|
Wow, that was a quick response! Thank you! Yes, that works and that's how I implemented it now. Just a few comments:
|
Beta Was this translation helpful? Give feedback.
-
That makes sense as
That's actually not an uncommon thing precisely for the reason of conversion. I believe that in the future you'd be able to use something like do yeet ContextSelector { details };
Sure, feel free to send in a PR adding to the examples section. |
Beta Was this translation helpful? Give feedback.
-
|
For my case, because I bubble up errors, just boxing the source was sufficient to reduce the stack size of Result. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a library where my error enum variants are getting too big (in struct size, > 128 bytes) and clippy complains.
I wanted to explore how to Box the error variant, but I'm not sure this is easily possible:
The opaque example almost looks like what I want (but with
pub struct Error(pub Box<InnerError>);). This does not translate 1:1 to Boxed: E.g. it only implementsFrom<Box<InnerError>> for Errorbut noFrom<InnerError>(but I can implement that manually).Also, while the example shows that this compiles:
I would actually like a
-> Result<(), Error>which breaks the example.Is there an easy way to do this? (i.e. without littering the already-verbose
context(...)with an additionalmap_err(BoxedError::from))Ideally, I would just define my Result type as
pub type Result<T> = std::result::Result<T, Box<Error>>;and tell derive(snafu) to deriveimpl IntoError<Box<Error>> for XxxSnafuautomatically (or just make the enum boxed when being told to). Do you think that is a good idea? Do you see better ways to achieve this?Beta Was this translation helpful? Give feedback.
All reactions