Consider the following code with a struct S
with a constrained generic type parameter Idx
and a default value for Idx
.
use num::{PrimInt, Unsigned};
struct S<Idx = u32>
where
Idx: Unsigned + PrimInt, {
// ... Some fields
}
impl<Idx: Unsigned + PrimInt> Clone for S<Idx> {
fn clone(&self) -> Self {
S {}
}
}
impl<Idx: Unsigned + PrimInt> Eq for S<Idx> {
fn eq(&self, rhs: &Self) -> bool {
true
}
}
I would like to implement a bunch of traits for S
, but I find always specifying the constraints for the Idx
type parameter tedious. If I don't specify Idx
on a trait implementation, the code compiles but only has an implementation for Idx = u32
.
Is there some convenience syntax where I don't have to specify the Idx: Unsigned + PrimInt
all the time but still correctly implements the traits?