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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
use super::std_reexports::*;
use derivative::Derivative;
use shrinkwraprs::Shrinkwrap;
pub type PhantomData2<T1,T2> = PhantomData<(PhantomData <T1>, PhantomData<T2>)>;
pub type PhantomData3<T1,T2,T3> = PhantomData2<PhantomData2<T1,T2>, PhantomData<T3>>;
pub type PhantomData4<T1,T2,T3,T4> = PhantomData2<PhantomData3<T1,T2,T3>, PhantomData<T4>>;
pub type PhantomData5<T1,T2,T3,T4,T5> = PhantomData2<PhantomData4<T1,T2,T3,T4>, PhantomData<T5>>;
pub type PhantomData6<T1,T2,T3,T4,T5,T6> = PhantomData2<PhantomData5<T1,T2,T3,T4,T5>, PhantomData<T6>>;
pub type PhantomData7<T1,T2,T3,T4,T5,T6,T7> = PhantomData2<PhantomData6<T1,T2,T3,T4,T5,T6>, PhantomData<T7>>;
pub type PhantomData8<T1,T2,T3,T4,T5,T6,T7,T8> = PhantomData2<PhantomData7<T1,T2,T3,T4,T5,T6,T7>, PhantomData<T8>>;
pub type PhantomData9<T1,T2,T3,T4,T5,T6,T7,T8,T9> = PhantomData2<PhantomData8<T1,T2,T3,T4,T5,T6,T7,T8>, PhantomData<T9>>;
#[derive(Derivative)]
#[derive(Shrinkwrap)]
#[shrinkwrap(mutable)]
#[derivative(Clone (bound="T:Clone"))]
#[derivative(Default (bound="T:Default"))]
#[derivative(Debug (bound="T:Debug"))]
pub struct WithPhantom<T, P=()> {
#[shrinkwrap(main_field)]
pub without_phantom: T,
phantom: PhantomData<P>
}
impl<T, P> WithPhantom<T, P> {
pub fn new(without_phantom: T) -> Self {
let phantom = PhantomData;
Self { without_phantom, phantom }
}
}
pub trait PhantomConversions: Sized {
fn phantom_into<P>() -> P where Self:PhantomInto<P> {
PhantomData::<Self>.into()
}
fn phantom_from<P:PhantomInto<Self>>() -> Self {
PhantomData::<P>.into()
}
}
impl<T> PhantomConversions for T {}
pub trait PhantomInto<T> = where PhantomData<Self>: Into<T>;