derive_more/
as.rs
1use core::marker::PhantomData;
9
10pub struct Conv<Frm: ?Sized, To: ?Sized>(PhantomData<(*const Frm, *const To)>);
12
13impl<Frm: ?Sized, To: ?Sized> Default for Conv<Frm, To> {
14 fn default() -> Self {
15 Self(PhantomData)
16 }
17}
18
19pub trait ExtractRef {
21 type Frm;
23 type To;
25
26 fn __extract_ref(&self, frm: Self::Frm) -> Self::To;
28}
29
30impl<'a, T> ExtractRef for &Conv<&'a T, T>
31where
32 T: ?Sized,
33{
34 type Frm = &'a T;
35 type To = &'a T;
36
37 fn __extract_ref(&self, frm: Self::Frm) -> Self::To {
38 frm
39 }
40}
41
42impl<'a, Frm, To> ExtractRef for Conv<&'a Frm, To>
43where
44 Frm: AsRef<To> + ?Sized,
45 To: ?Sized + 'a,
46{
47 type Frm = &'a Frm;
48 type To = &'a To;
49
50 fn __extract_ref(&self, frm: Self::Frm) -> Self::To {
51 frm.as_ref()
52 }
53}
54
55impl<'a, T> ExtractRef for &Conv<&'a mut T, T>
56where
57 T: ?Sized,
58{
59 type Frm = &'a mut T;
60 type To = &'a mut T;
61
62 fn __extract_ref(&self, frm: Self::Frm) -> Self::To {
63 frm
64 }
65}
66
67impl<'a, Frm, To> ExtractRef for Conv<&'a mut Frm, To>
68where
69 Frm: AsMut<To> + ?Sized,
70 To: ?Sized + 'a,
71{
72 type Frm = &'a mut Frm;
73 type To = &'a mut To;
74
75 fn __extract_ref(&self, frm: Self::Frm) -> Self::To {
76 frm.as_mut()
77 }
78}