I try to test a variables whether if satisfied trait Future, code as following:
use std::future::Future;
use ::core::marker::PhantomData;
fn val_implement<T> (_: T)-> bool {
// println!("type of v: {:?}", type_of(v));
trait SpecializedValue {
fn value()-> bool { true }
}
impl<T: ?Sized> SpecializedValue for PhantomData<T>
where T: Future
{}
PhantomData::<T>::value()
}
async fn test_future_1()-> usize {
200
}
fn test_future_2()-> impl Future {
async {
100
}
}
fn main() {
let f1 = test_future_1();
let f2 = test_future_2();
let is_future = val_implement(f1);
let is_future = val_implement(f2);
}
But neither f1 nor f2 is compile error:
| pub struct PhantomData<T: ?Sized>;
| ---------------------------------- doesn't satisfy `PhantomData<T>: SpecializedValue`
|
= note: the method `value` exists but the following trait bounds were not satisfied:
`<T as Future>`
which is required by `PhantomData<T>: SpecializedValue`
`T: Future`
which is required by `PhantomData<T>: SpecializedValue`
when I delete the bounds of Future, it will be compiled success.
impl<T: ?Sized> SpecializedValue for PhantomData<T>
// where T: Future
{}
Why variables f1
and f2
are not satisfied trait Future
even if I special its type impl Future
?
Please help, Thanks!