In rust, you can automatically implement a trait for any type that implements some other combination of traits. Ie:
impl<T: Foo + Bar> SomeTrait for T {
some_function(&self) {
/*...*/
}
}
What I'm trying to do is define a relationship where Foo
and Bar
are both enough to implement SomeTrait
by themselves. Basically, something like this:
impl<T: Foo> SomeTrait for T {
some_function(&self) {
/*...*/
}
}
impl<T: Bar> SomeTrait for T {
some_function(&self) {
/*...*/
}
}
This won't compile, because you're implementing SomeTrait
for T
twice and the compiler can't possibly know what to do in the case where T: Foo + Bar
, but it'd be really nice to be able to do this.
Is there some way to "abstract" around this problem so that I can call some_function()
on a T
that implements Foo
OR Bar
? Or am I stuck with having to pick only one implementation?