Basically, I'm looking for a way to have a trait method that is only valid for specific assoc types.
I've done something similar to here to get it to work for default impl: https://stackoverflow.com/q/64100386
However, I'm struggling to get it to work when I don't want to use the default impl. It appears that the trait bound isn't applying to the input, just the output of the function. Any ideas how to get around this?
Playground link
Code:
trait MyTrait {
type Datatype;
fn do_something(&self) -> Self::Datatype
where
Self: MyTrait<Datatype = f64>,
{
0.0
}
}
struct MyStruct<T>(T);
impl<T> MyTrait for MyStruct<T> {
type Datatype = T;
fn do_something(&self) -> Self::Datatype
where
Self: MyTrait<Datatype = f64>,
{
self.0
}
}