I have a trait that does work on data which is bounded in several dimensions, so I create it with const generics allowing me to define those bounds:
trait Transmogrifier<const N: usize, const W: usize, const B: usize> {
// ...
}
Then, I have another trait which does some other work, which itself uses a Transmogrifier
, so I've got to create this fairly unpleasant looking trait:
trait Foo<T: Transmogrifier<N, W, B>, const N: usize, const W: usize, const B: usize> {
fn init(transmogrifier: T) -> Self;
// ...
}
I don't need N
, W
, and B
in Foo
implementations, but the compiler complains if I don't add them in there, so meh.
Now, though, I've determined that I need to extend the Transmogrifier
to also take a couple of ancillary traits, that provide different ways of doing some of the transmogrifier's operations, which themselves use some of the const generics for their own purposes, leaving me with this absolute horror show:
trait Spindler<const N: usize> {
// ...
}
trait Mutilator<const W: usize> {
// ...
}
trait Transmogrifier<S: Spindler<N>, M: Mutilator<W>, const N: usize, const W: usize, const B: usize> {
// ...
}
trait Foo<T: Transmogrifier<S, M, N, W, B>, S: Spindler<N>, M: Mutilator<W>, const N: usize, const W: usize, const B: usize> {
fn init(transmogrifier: T) -> Self;
// ...
}
At this point, all the duplication and lengthy lists of capital letters is doing my head in, and I'm starting to think I've made a terrible design blunder and there's a different way of doing this. Is there a better way of doing this, a syntax shortcut I haven't found, or is this just how it's going to be, and I've just got to go limp and think of Clippy?