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
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
//! helper functions for limiting lifetimes
use super::*;

/*pub unsafe trait ShortLT: Sized {
    type Dest: Sized;

    fn short_lt(self) -> Self::Dest;
}

/*pub unsafe trait ShortLTBase {
    type _Dest: Sized;

    fn _short_lt(self) -> Self::_Dest;
}

unsafe impl<T> ShortLTBase for T where T: ShortLT + Sized, T::Dest: Sized {
    type _Dest = T::Dest;

    fn _short_lt(self) -> Self::_Dest {
        unsafe {
            std::mem::transmute::<Self,T::_Dest>(self)
        }
    }
}*/

macro_rules! simp {
    () => {
        fn short_lt(self) -> Self::Dest {
            unsafe {
                std::mem::transmute::<Self,Self::Dest>(self)
            }
        }
    };
}

unsafe impl<'l,'s,E> ShortLT for Resolvable<'l,E> where 'l: 's, E: Env {
    type Dest = Resolvable<'s,E>;

    fn short_lt(self) -> Resolvable<'s,E> {
        short_resolvable(self)
    }
}*/

impl<'l:'s,'s,E: Env> Resolvable<'l,E> {
    pub fn short_lt(self) -> Resolvable<'s,E> {
        match self {
            Resolvable::Widget(w) => Resolvable::Widget(w.short_lt()),
            Resolvable::Path(p) => Resolvable::Path(p),
        }
    }
}
impl<'l:'s,'s,E: Env> ResolvableMut<'l,E> {
    pub fn short_lt(self) -> ResolvableMut<'s,E> {
        match self {
            ResolvableMut::Widget(w) => ResolvableMut::Widget(w.short_lt()),
            ResolvableMut::Path(p) => ResolvableMut::Path(p),
        }
    }
}

pub trait ShortResolvableVec<'l,'s,E> where 'l: 's, E: Env {
    fn short_lt(self) -> Vec<Resolvable<'s,E>>;
}
impl<'l,'s,E> ShortResolvableVec<'l,'s,E> for Vec<Resolvable<'l,E>> where 'l: 's, E: Env {
    fn short_lt(self) -> Vec<Resolvable<'s,E>> {
        unsafe{
            std::mem::transmute::<Vec<Resolvable<'l,E>>,Vec<Resolvable<'s,E>>>(self)
        }
    }
}

impl<'l:'s,'s,E: Env> Resolved<'l,E> {
    pub fn short_lt(self) -> Resolved<'s,E> {
        Resolved{
            wref: self.wref.short_lt(),
            path: self.path,
            stor: self.stor,
        }
    }
}
impl<'l:'s,'s,E: Env> ResolvedMut<'l,E> {
    pub fn short_lt(self) -> ResolvedMut<'s,E> {
        ResolvedMut{
            wref: self.wref.short_lt(),
            path: self.path,
        }
    }
}

pub trait ShortWidgetRef<'l,'s,E> where 'l: 's, E: Env {
    fn short_lt(self) -> WidgetRef<'s,E>;
}
impl<'l,'s,E> ShortWidgetRef<'l,'s,E> for WidgetRef<'l,E> where 'l: 's, E: Env {
    fn short_lt(self) -> WidgetRef<'s,E> {
        unsafe{
            std::mem::transmute::<WidgetRef<'l,E>,WidgetRef<'s,E>>(self)
        }
    }
}
pub trait ShortWidgetRefMut<'l,'s,E> where 'l: 's, E: Env {
    fn short_lt(self) -> WidgetRefMut<'s,E>;
}
impl<'l,'s,E> ShortWidgetRefMut<'l,'s,E> for WidgetRefMut<'l,E> where 'l: 's, E: Env {
    fn short_lt(self) -> WidgetRefMut<'s,E> {
        unsafe{
            std::mem::transmute::<WidgetRefMut<'l,E>,WidgetRefMut<'s,E>>(self)
        }
    }
}

pub trait ShortRefWidgetRef<'l,'s,'y,E> where 'l: 's, 's: 'y, 'l: 'y, E: Env {
    fn short_lt(self) -> &'y dyn Widget<'s,E>;
}
impl<'l,'s,'y,E> ShortRefWidgetRef<'l,'s,'y,E> for &'y dyn Widget<'l,E> where 'l: 's, 's: 'y, 'l: 'y, E: Env {
    fn short_lt(self) -> &'y dyn Widget<'s,E> {
        unsafe{
            std::mem::transmute::<&'y dyn Widget<'l,E>,&'y dyn Widget<'s,E>>(self)
        }
    }
}
pub trait ShortRefWidgetMut<'l,'s,'y,E> where 'l: 's, 's: 'y, 'l: 'y, E: Env {
    fn short_lt(self) -> &'y mut dyn WidgetMut<'s,E>;
}
impl<'l,'s,'y,E> ShortRefWidgetMut<'l,'s,'y,E> for &'y mut dyn WidgetMut<'l,E> where 'l: 's, 's: 'y, 'l: 'y, E: Env {
    fn short_lt(self) -> &'y mut dyn WidgetMut<'s,E> {
        unsafe{
            std::mem::transmute::<&'y mut dyn WidgetMut<'l,E>,&'y mut dyn WidgetMut<'s,E>>(self)
        }
    }
}