1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
The `DispatchFromDyn` trait was implemented on something which is not a pointer
or a newtype wrapper around a pointer.
Erroneous code example:
```compile_fail,E0378
#![feature(dispatch_from_dyn)]
use std::ops::DispatchFromDyn;
struct WrapperExtraField<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`.
```
#![feature(dispatch_from_dyn, unsize)]
use std::{
marker::Unsize,
ops::DispatchFromDyn,
};
struct Ptr<T: ?Sized>(*const T);
impl<T: ?Sized, U: ?Sized> DispatchFromDyn<Ptr<U>> for Ptr<T>
where
T: Unsize<U>,
{}
```
Another example:
```
#![feature(dispatch_from_dyn)]
use std::{
ops::DispatchFromDyn,
marker::PhantomData,
};
struct Wrapper<T> {
ptr: T,
_phantom: PhantomData<()>,
}
impl<T, U> DispatchFromDyn<Wrapper<U>> for Wrapper<T>
where
T: DispatchFromDyn<U>,
{}
```
|