Hello Rustaceans.
I want to implement separate test methods for different association types.
Code:
use std::{future::Future, pin::Pin};
pub type BoxFuture<T> = Pin<Box<dyn Future<Output = T> + Send + 'static>>;
trait A {
fn test(&self) -> BoxFuture<usize>;
}
trait B {
type TestRet: Future<Output = usize>;
fn test(&self) -> Self::TestRet;
}
impl<T: B> A for T
{
fn test(&self) -> BoxFuture<usize> {
Box::pin(self.test())
}
}
impl<T: B<TestRet = BoxFuture<usize>>> A for T // conflicting implementations of trait `A`
{
fn test(&self) -> BoxFuture<usize> {
self.test()
}
}
fn main() {
}
Error:
error[E0119]: conflicting implementations of trait `A`
--> src\main.rs:22:1
|
15 | impl<T: B> A for T
| ------------------ first implementation here
...
22 | impl<T: B<TestRet = BoxFuture<usize>>> A for T // conflicting implementations of trait `A`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation
For more information about this error, try `rustc --explain E0119`.
Is there a practice similar to the following
impl<T: B<TestRet != BoxFuture<usize>> A for T
{
fn test(&self) -> BoxFuture<usize> {
Box::pin(self.test())
}
}