unstructured/core/
from.rs1use crate::*;
2
3macro_rules! from_imp {
4 ( &{ $($ref_ty:ty, $ref_v:ident)* } *{ $($ty:ty, $v:ident)* } ) => {
5 $(
6 impl<T: UnstructuredDataTrait> From<&$ref_ty> for Unstructured<T> {
7 fn from(n: &$ref_ty) -> Self {
8 Unstructured::<T>::$ref_v(n.to_owned())
9 }
10 }
11 )*
12
13 $(
14 impl<T: UnstructuredDataTrait> From<$ty> for Unstructured<T> {
15 fn from(n: $ty) -> Self {
16 Unstructured::<T>::$v(n as $ty)
17 }
18 }
19 )*
20 };
21}
22
23impl<T: Into<Number>, Q: UnstructuredDataTrait> From<T> for Unstructured<Q> {
24 fn from(n: T) -> Self {
25 Self::Number(n.into())
26 }
27}
28
29from_imp! {
30 &{
31 bool,Bool
32 char,Char
33 String,String str,String
34 Vec<u8>,Bytes
35 Sequence<T>,Seq
36 Mapping<T>,Map
37 Option<Box<Unstructured<T>>>,Option
38 Box<Unstructured<T>>,Newtype
39 }
40
41 *{
42 bool,Bool
43 char,Char
44 String,String
45 Vec<u8>,Bytes
46 Sequence<T>,Seq
47 Mapping<T>,Map
48 Option<Box<Unstructured<T>>>,Option
49 Box<Unstructured<T>>,Newtype
50 }
51}