The DispatchFromDyn trait was implemented on something which is not a pointer
or a newtype wrapper around a pointer.
Erroneous code example:
#![allow(unused)]#![feature(dispatch_from_dyn)]fnmain() {
use std::ops::DispatchFromDyn;
structWrapperExtraField<T> {
ptr: T,
extra_stuff: i32,
}
impl<T, U> DispatchFromDyn<WrapperExtraField<U>> for WrapperExtraField<T>
where
T: DispatchFromDyn<U>,
{}
}
ⓘ
The DispatchFromDyn trait currently can only be implemented for
builtin pointer types and structs that are newtype wrappers around them
— that is, the struct must have only one field (except for PhantomData),
and that field must itself implement DispatchFromDyn.
#![allow(unused)]#![feature(dispatch_from_dyn, unsize)]fnmain() {
use std::{
marker::Unsize,
ops::DispatchFromDyn,
};
structPtr<T: ?Sized>(*const T);
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
where
T: Unsize<U>,
{}
}
Another example:
#![allow(unused)]#![feature(dispatch_from_dyn)]fnmain() {
use std::{
ops::DispatchFromDyn,
marker::PhantomData,
};
structWrapper<T> {
ptr: T,
_phantom: PhantomData<()>,
}
impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
where
T: DispatchFromDyn<U>,
{}
}