Replies: 3 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.
-
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 Error
but 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 XxxSnafu
automatically (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