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
use crate::*;

macro_rules! from_imp {
    ( &{ $($ref_ty:ty, $ref_v:ident)* } *{ $($ty:ty, $v:ident)* } ) => {
        $(
            impl<T: UnstructuredDataTrait> From<&$ref_ty> for Unstructured<T> {
                fn from(n: &$ref_ty) -> Self {
                    Unstructured::<T>::$ref_v(n.to_owned())
                }
            }
        )*

        $(
            impl<T: UnstructuredDataTrait> From<$ty> for Unstructured<T> {
                fn from(n: $ty) -> Self {
                    Unstructured::<T>::$v(n as $ty)
                }
            }
        )*
    };
}

impl<T: Into<Number>, Q: UnstructuredDataTrait> From<T> for Unstructured<Q> {
    fn from(n: T) -> Self {
        Self::Number(n.into())
    }
}

from_imp! {
    &{
        bool,Bool
        char,Char
        String,String str,String
        Vec<u8>,Bytes
        Sequence<T>,Seq
        Mapping<T>,Map
        Option<Box<Unstructured<T>>>,Option
        Box<Unstructured<T>>,Newtype
    }

    *{
        bool,Bool
        char,Char
        String,String
        Vec<u8>,Bytes
        Sequence<T>,Seq
        Mapping<T>,Map
        Option<Box<Unstructured<T>>>,Option
        Box<Unstructured<T>>,Newtype
    }
}