Why use generics instead of associated types in Handler definition? #3389
-
SummaryI am currently trying to build service contract framework and integrate it with axum as one of server-sides. The problem I encountered is that to enforce a subset of endpoint arguments I need to check the arguments, that handler accepts. And, as Hence, I have the next question: why use generics instead of associated types in Handler definition (and may be some other ones as well)? There is no use case on my mind (and pub trait Handler<S>
// constraints ...
{
type FromRequestMarker; // Either ViaParts or ViaRequest
type Args;
/// ...etc
} axum version0.8.4 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Both of these things are not actually used by the trait, they exist to work around coherence. Since a type can (from the type system's perspective) implement both |
Beta Was this translation helpful? Give feedback.
Both of these things are not actually used by the trait, they exist to work around coherence. Since a type can (from the type system's perspective) implement both
Fn(X)
andFn(Y)
(the arguments are a generic type for theFn
traits as well, not an associated type), we need the extra generics so all the impls we have forHandler
don't conflict with each other.