How to constrain the association type not to be equal to a type?

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())
    }
}

This is impossible on stable Rust.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.