#How to stop these implementation overlaps

31 messages · Page 1 of 1 (latest)

icy gyro
#
GitHub

Ergonomic and modular web framework built with Tokio, Tower, and Hyper - tokio-rs/axum

GitHub

Ergonomic and modular web framework built with Tokio, Tower, and Hyper - tokio-rs/axum

noble meadow
#

post the error

#

but more directly, couldn’t String be interpreted as the context?

icy gyro
#

Yes it can, fair point. Error is just conflicting implementations of trait ToolMethod<(std::string::String,), std::string::String, _, _, _>

noble meadow
#

well uhm

#

you know the problem

#

what’s your desired solution?

icy gyro
#

The ideal solution would be if there were a way to make it work as is. It's all my crate so I can change the trait signature and bounds however I need to so the syntax I'm aiming for will work.

noble meadow
#

How do you expect the compiler to know whether you want the C = String impl or the String impl?

#

should the user have to specify by some turbofish?

#

in fact, those impls aren’t different, why are they even both there?

#

oh wait, I see they’re a bit different

icy gyro
noble meadow
#

e.g. maybe offering two functions for the String and other context case

icy gyro
#

Could wrapping C in a newtype work? Just something like Context<C>

#

Sort of like Axum's State extractor

noble meadow
#

Yeah, that would work

#

Another alternative might be defining a trait that C types are required to implement

#

then if you don’t implement this trait for String, Rust knows that C: YourTrait and String are always disjoint

icy gyro
noble meadow
#

so it’s not ideal

#

i mean you could implement the marker for Arc<impl Marker>

#

but still

icy gyro
#

Newtype seems the most elegant solution IMO

noble meadow
#

mm

#

newtypes are always nice

icy gyro
#

Works like a charm, thanks for your help. Now to add the other permutations