Hello Rustaceans,
I'm currently rewriting parts of a test library and struggle with how to implement a function that takes multiple types of closure via Into for a part of it's API(either normal or async; either T or Result<T, Status>, where T implements a trait called Message. Unfortunately both Status and Message are provided by different crates).
I want to do this so that the testing crate is more flexible in how the user can use it(less necessary boiler plate; the logic will be handled inside).
I wrote some stub code that you can access here if you roughly want to see what I intend to do(apologies for the mess of generics, I'm planing to majorly refactor this later).
Unfortunately this fails due to conflicting impls for the From trait, probably because the compiler can't be sure that e.g. Message won't be implemented by Result<T, Status> etc I'm assuming?
implemenations
How could I describe such logic in Rust code to avoid the conflict and in general: How should I, in general when writing Rust, proceed when compilation fails due to Rust thinking that there may be multiple conflicting implementations?
I often can't think of a way to express 'this generic type implements either trait A or trait B, which are mutually EXCLUSIVE. (Sort of like an enum)' in Rusts typesystem.
(I would like to avoid choosing completely arbitrary types, like e.g. String, to implement a trait for as I've been too many times in the situation of having to find weird workarounds, because a library only implemented something for specific types to avoid having to deal with the type system. Hard to maintain, hard to reason through code and I'm still looking for a best practice that won't quickly turn into another footgun)
A browser interface to the Rust compiler to experiment with the language