Error handling with generics and traits

I'm trying to use the "multiple error type into one using enum" approach to handle associated errors on types I use in my library, accessed only through generics and traits (in other words I do not know, or control what actual types are going to be used here).

The playground link with some comments is here: Rust Playground

The error I'm getting is: conflicting implementations of trait std::convert::From<UnifiedError<_, >>for typeUnifiedError<, _>:

How can I make use of From for these generics/associated types such that ? would work? Do I have to use manual boilerplate and construct the error enum manually for each operation ala if func().is_ok() { return Err(MyError::fromSecondGeneric(...) } ??

1 Like

In the following trait implementation

// why is there a conflicting implementation in core???
impl<S1, S2> From<S1::Error> for UnifiedError<S1, S2>
where
    S1: SomeTrait,
    S2: SomeTrait,
{

What if we have a type S1 whose associated type Error is UnifiedError<U, V> ? In original snippet of code there is no-where such restriction is specified.

And it looks like we cannot do negative trait bound, atleast not yet.

There are more information available here.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.