Skip to content

Can’t define traits on TryIntoError #396

@mina86

Description

@mina86

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:

#[derive(derive_more::TryInto)]
#[try_into(error = MyError)]
pub enum Blah {
    Foo(third_party::Foo),
    Bar(third_party::Bar),
    Baz(third_party::Baz),
}

#[derive(derive_more::From)]
struct MyError(derive_more::TryIntoError<Blah>);

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?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions