Im trying to cast a generic type (represented as PhantomData<V>) into a trait (which is implemented for PhantomData<V>) through a method. Can someone explain why rust does not implement Into for dyn Trait if the type implements that trait?
pub trait Trait {
}
impl<V> Trait for PhantomData<V> {
}
pub fn test() {
// Trying to cast PhantomData<f32> to Trait through the method. (PhantomData<f32> implements Trait)
let output: Box<dyn Trait> = cast::<dyn Trait, f32>();
// ^^^ the trait `From<PhantomData<f32>>` is not implemented for `Box<dyn Trait>`
}
pub fn cast<A: ?Sized, V>() -> Box<A> where PhantomData<V>: Into<Box<A>> {
PhantomData::<V>.into()
}