-
Notifications
You must be signed in to change notification settings - Fork 114
Closed
Labels
area/libs > error-stackAffects the `error-stack` crate (library)Affects the `error-stack` crate (library)category/enhancementNew feature or requestNew feature or requeststate/blockedThis pull request is currently blockedThis pull request is currently blocked
Description
Related Problem
Hello! I ran into a problem, which is better to show with example:
struct Foo;
impl<V> Foo for SomeTrait<V>
where
V: TryInto<Vec<u8>>,
<V as TryInto<Vec<u8>>>::Error: error_stack::Context,
{
fn do_stuff(&self, value: V) -> error_stack::Result<(), MyError> {
...
let my_vec: Vec<u8> = value.try_into().into_report().change_context(MyError);
...
}
}
struct Bar;
impl TryInto<Vec<u8>> for Bar {
type Error = error_stack::Report<TransformError>;
fn try_into(self) -> Result<Vec<u8>, Self::Error> {
/// Some serialization
}
}
fn main() {
let foo = Foo;
let bar = Bar;
let baz = "baz".to_owned();
foo.do_stuff(baz); // Good
foo.do_stuff(bar); // Error. The trait `StdError` is not implemented for `error_stack::Report<TransformationError>`
}I have implementation of SomeTrait that requires TryInto<Vec<u8>>::Error implement error_stack::Context. But Report is not impl Context and is not impl Error.
Proposed Solution
Implement Error for Report:
impl<E> std:error::Error for Report<E> {}It's simple and allows to write more abstract code. In other words Report will compatible with Errors
Alternatives
No response
Additional context
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area/libs > error-stackAffects the `error-stack` crate (library)Affects the `error-stack` crate (library)category/enhancementNew feature or requestNew feature or requeststate/blockedThis pull request is currently blockedThis pull request is currently blocked