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
use crate::{
    convert::{EmptyTryFromError, FromStructural, TryFromError, TryFromStructural},
    structural_aliases as sa,
};

tstr_aliases! {
    mod strings {
        Ok,
        Err,
        Some,
        None,
        field0=0,
    }
}

///////////////////////////////////////////////////////////////////////////////

_private_impl_getters_for_derive_enum! {
    impl[T,] Option<T>
    where[]
    {
        enum=Option
        drop_fields={just_fields,}
        variant_count=TS!(2),
        (
            Some,
            strings::Some,
            kind=regular,
            not_public(),
            fields((IntoVariantFieldMut,0:T,dropping(f0, 0),strings::field0))
        )
        (None,strings::None,kind=regular,not_public(),fields())
    }
}

impl<F, T> FromStructural<F> for Option<T>
where
    F: sa::OptionMove_ESI<T>,
{
    fn from_structural(this: F) -> Self {
        switch! {this;
            Some(x)=>Some(x),
            None=>None,
        }
    }
}

impl<F, T> TryFromStructural<F> for Option<T>
where
    F: sa::OptionMove_SI<T>,
{
    type Error = EmptyTryFromError;

    fn try_from_structural(this: F) -> Result<Self, TryFromError<F, Self::Error>> {
        Ok(switch! {this;
            Some(x)=>Some(x),
            None=>None,
            _=>return Err(TryFromError::with_empty_error(this)),
        })
    }
}

///////////////////////////////////////////////////////////////////////////////

_private_impl_getters_for_derive_enum! {
    impl[T,E,] Result<T,E>
    where[]
    {
        enum=Result
        drop_fields={just_fields,}
        variant_count=TS!(2),
        (
            Ok,
            strings::Ok,
            kind=regular,
            not_public(),
            fields((IntoVariantFieldMut,0:T,dropping(f0, 0),strings::field0))
        )
        (
            Err,
            strings::Err,
            kind=regular,
            not_public(),
            fields((IntoVariantFieldMut,0:E,dropping(f0, 0),strings::field0))
        )
    }
}

impl<F, T, E> FromStructural<F> for Result<T, E>
where
    F: sa::ResultMove_ESI<T, E>,
{
    fn from_structural(this: F) -> Self {
        switch! {this;
            Ok(x)=>Ok(x),
            Err(x)=>Err(x),
        }
    }
}

impl<F, T, E> TryFromStructural<F> for Result<T, E>
where
    F: sa::ResultMove_SI<T, E>,
{
    type Error = EmptyTryFromError;

    fn try_from_structural(this: F) -> Result<Self, TryFromError<F, Self::Error>> {
        Ok(switch! {this;
            Ok(x)=>Ok(x),
            Err(x)=>Err(x),
            _=>return Err(TryFromError::with_empty_error(this)),
        })
    }
}

///////////////////////////////////////////////////////////////////////////////