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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
extern crate proc_macro;
use ;
use TokenStream;
//TODO noWrap/wrapDepth -> giftwrap(noWrap/wrapDepth) in docs
pub
/// Derve macro for `From<T>` where `T` is the inner type(s) of your struct or enum.
///
/// Using `#[giftwrap(wrapDepth = n)]` `From` is derived for every type in the chain, which is useful for
/// types such as `Box<T>` and `Arc<Mutex<T>>`. Setting wrapDepth to 0 will derive for all inner
/// types. Default depth is 1.
///
/// Any enum variant annotated with `#[giftwrap(noWrap = true)]` will be ignored.
///
/// # Example
/// ```ignore
/// use std::sync::{Arc, Mutex};
/// use giftwrap::Wrap;
///
/// #[derive(Wrap)]
/// enum SomeEnum {
/// Number(i64),
/// Text(String),
/// #[giftwrap(wrapDepth = 0)]
/// DeepVariant(Arc<Mutex<bool>>),
/// #[giftwrap(noWrap = true)]
/// Real(f64),
/// }
///
/// //would generate
/// impl From<i64> for SomeEnum {
/// fn from(f: i64) -> Self {
/// SomeEnum::Number(f)
/// }
/// }
///
/// impl From<String> for SomeEnum {
/// fn from(f: String) -> Self {
/// SomeEnum::Text(f)
/// }
/// }
///
/// impl From<Arc<Mutex<bool>>> for SomeEnum {
/// fn from(f: Arc<Mutex<bool>>) -> Self {
/// SomeEnum::DeepVariant(f)
/// }
/// }
///
/// impl From<Mutex<bool>> for SomeEnum {
/// fn from(f: Mutex<bool>) -> Self {
/// SomeEnum::DeepVariant(Arc::<_>::from(f))
/// }
/// }
///
/// impl From<bool> for SomeEnum {
/// fn from(f: bool) -> Self {
/// SomeEnum::DeepVariant(Arc::<_>::from(Mutex::<_>::from(f)))
/// }
/// }
/// ```
/// Derve macro for `impl From<S> for T` and `impl TryFrom<E> for T` for structs (`S`) and enums (`E`) where `T` is the inner type(s).
///
/// Any enum variant annotated with `#[giftwrap(noUnwrap = true)]` will be ignored.
///
/// # Example
/// ```ignore
/// use std::convert::TryFrom;
/// use giftwrap::Unwrap;
///
/// #[derive(Unwrap)]
/// enum SomeEnum {
/// Number(i64),
/// Text(String),
/// #[giftwrap(noUnwrap = true)]
/// Real(f64),
/// }
///
/// //would generate
/// impl TryFrom<SomeEnum> for i64 {
/// type Error = &'static str;
///
/// fn try_from(f: SomeEnum) -> Self {
/// match f {
/// SomeEnum::Number(v) => v,
/// SomeEnum::Text(_) => "Cannot convert SomeEnum::Text into i64",
/// //...
/// }
/// }
/// }
///
/// impl TryFrom<SomeEnum> for String {
/// type Error = &'static str;
///
/// fn try_from(f: SomeEnum) -> Self {
/// match f {
/// SomeEnum::Text(v) => v,
/// SomeEnum::Number(_) => "Cannot convert SomeEnum::Number into String",
/// //...
/// }
/// }
/// }
/// ```
pub
pub