You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I’m working with a third-party crate which defines a ClientError type and a From<&'static str> trait for that type. Further, the crate has a generic method with the following two bounds: T: TryInto<Foo> and T::Error: Into<ClientError>. Lastly, in my code I have an enum whose one of the variant carries Foo value and uses derive_more::TryInto to define the required TryInto<Foo> implementation.
With derive_more 0.99 this worked fine. derive_more created the implementation with &'static str error which satisfies Into<ClientError> bound.
Sadly, with derive_more 1.0 the conversion error is now TryIntoError which cannot be converted into ClientError and because both of those types are third-party I cannot add the implementation.
I wonder if it would be possible to add a customisable error. For example I could then do:
and then define all necessary conversions on MyError. Even more flexible if I could define error type and constructor separately.
This actually is something I’ve suggested a while back, see #315, and back then I concluded that TryIntoError would work for my case. Alas, turns out not quite.
PS. variant_names and output_type be pub?
The text was updated successfully, but these errors were encountered:
I think this is very reasonable. I think the best solution would contain the following three things:
Allow providing an error type. This error type should have a From implementation for TryIntoError.
Allow providing a custom constructor for an error type by using a closure that takes a TryIntoError.
Make output_type and variant_names public members of TryIntoError. I think we should probably make variant_names an &'static [] in that case in that case.
I’m working with a third-party crate which defines a
ClientError
type and aFrom<&'static str>
trait for that type. Further, the crate has a generic method with the following two bounds:T: TryInto<Foo>
andT::Error: Into<ClientError>
. Lastly, in my code I have an enum whose one of the variant carriesFoo
value and usesderive_more::TryInto
to define the requiredTryInto<Foo>
implementation.With derive_more 0.99 this worked fine. derive_more created the implementation with
&'static str
error which satisfiesInto<ClientError>
bound.Sadly, with derive_more 1.0 the conversion error is now
TryIntoError
which cannot be converted intoClientError
and because both of those types are third-party I cannot add the implementation.I wonder if it would be possible to add a customisable error. For example I could then do:
and then define all necessary conversions on
MyError
. Even more flexible if I could define error type and constructor separately.This actually is something I’ve suggested a while back, see #315, and back then I concluded that TryIntoError would work for my case. Alas, turns out not quite.
PS. variant_names and output_type be pub?
The text was updated successfully, but these errors were encountered: