Struct syn_args::Formal

source ·
pub struct Formal {}

Implementations§

source§

impl Formal

source

pub fn new() -> Self

Examples found in repository?
examples/test-expand.rs (line 99)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for ModuleArgs {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
pub struct ModuleSubObj {
    pub global: def::Option<def::Bool>,
    pub imports: def::Array<def::Ident>,
    pub sub: def::Option<Sub>,
}
#[automatically_derived]
impl ::core::fmt::Debug for ModuleSubObj {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "ModuleSubObj", "global", &self.global, "imports", &self.imports, "sub", &&self.sub)
    }
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for ModuleSubObj {}
#[automatically_derived]
impl ::core::cmp::PartialEq for ModuleSubObj {
    #[inline]
    fn eq(&self, other: &ModuleSubObj) -> bool {
        self.global == other.global && self.imports == other.imports && self.sub == other.sub
    }
}
impl TryFrom<&syn_args::Value> for ModuleSubObj {
    type Error = syn::Error;
    fn try_from(v: &syn_args::Value) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(_) = v {
            return Ok(ModuleSubObj {
                global: syn_args::Transform::new(v, "global").try_into()?,
                imports: syn_args::Transform::new(v, "imports").try_into()?,
                sub: syn_args::Transform::new(v, "sub").try_into()?,
            });
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Invalid args"))
    }
}
impl TryFrom<syn_args::Value> for ModuleSubObj {
    type Error = syn::Error;
    fn try_from(v: syn_args::Value) -> Result<Self, Self::Error> {
        ModuleSubObj::try_from(&v)
    }
}
impl syn_args::ArgsParse for ModuleSubObj {
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for ModuleSubObj {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
pub struct Sub {
    pub value: def::Bool,
}
#[automatically_derived]
impl ::core::fmt::Debug for Sub {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "Sub", "value", &&self.value)
    }
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Sub {}
#[automatically_derived]
impl ::core::cmp::PartialEq for Sub {
    #[inline]
    fn eq(&self, other: &Sub) -> bool {
        self.value == other.value
    }
}
impl TryFrom<&syn_args::Value> for Sub {
    type Error = syn::Error;
    fn try_from(v: &syn_args::Value) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(_) = v {
            return Ok(Sub { value: syn_args::Transform::new(v, "value").try_into()? });
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Invalid args"))
    }
}
impl TryFrom<syn_args::Value> for Sub {
    type Error = syn::Error;
    fn try_from(v: syn_args::Value) -> Result<Self, Self::Error> {
        Sub::try_from(&v)
    }
}
impl syn_args::ArgsParse for Sub {
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for Sub {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
pub struct SubWrap {
    pub s1: Sub,
    pub s2: Sub,
}
#[automatically_derived]
impl ::core::fmt::Debug for SubWrap {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "SubWrap", "s1", &self.s1, "s2", &&self.s2)
    }
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for SubWrap {}
#[automatically_derived]
impl ::core::cmp::PartialEq for SubWrap {
    #[inline]
    fn eq(&self, other: &SubWrap) -> bool {
        self.s1 == other.s1 && self.s2 == other.s2
    }
}
impl TryFrom<&syn_args::Value> for SubWrap {
    type Error = syn::Error;
    fn try_from(v: &syn_args::Value) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(_) = v {
            return Ok(SubWrap { s1: syn_args::Transform::new(v, "s1").try_into()?, s2: syn_args::Transform::new(v, "s2").try_into()? });
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Invalid args"))
    }
}
impl TryFrom<syn_args::Value> for SubWrap {
    type Error = syn::Error;
    fn try_from(v: syn_args::Value) -> Result<Self, Self::Error> {
        SubWrap::try_from(&v)
    }
}
impl syn_args::ArgsParse for SubWrap {
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for SubWrap {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
fn test_formal_f1() {
    let f = Formal::new();
    let args = f.parse("F(1, 3)").unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", args));
    };
    let res = ModuleArgs::try_from(&args).unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", res));
    };
    match (&res, &ModuleArgs::F1(def::Int(1), def::Int(3))) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val, &*right_val, ::core::option::Option::None);
            }
        }
    };
}
fn test_formal_f2() {
    let f = Formal::new();
    let args = f.parse("F(1)").unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", args));
    };
    let res = ModuleArgs::try_from(&args).unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", res));
    };
    match (&res, &ModuleArgs::F2(def::Int(1))) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val, &*right_val, ::core::option::Option::None);
            }
        }
    };
}
More examples
Hide additional examples
examples/test.rs (line 33)
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
fn test_formal_f1() {
    let f = Formal::new();

    // fm.parse("F(Object{ a: Int, b: Optional(Int) }, Array(Int))");
    let args = f.parse("F(1, 3)").unwrap();
    // let args = f.parse("F(1)").unwrap();
    // let args = f.parse("F(Hello)").unwrap();
    println!("{:?}", args);

    let res = ModuleArgs::try_from(&args).unwrap();
    println!("{:?}", res);

    assert_eq!(res, ModuleArgs::F1(def::Int(1), def::Int(3)));
}

fn test_formal_f2() {
    let f = Formal::new();

    let args = f.parse("F(1)").unwrap();
    // let args = f.parse("F(Hello)").unwrap();
    println!("{:?}", args);

    let res = ModuleArgs::try_from(&args).unwrap();
    println!("{:?}", res);

    assert_eq!(res, ModuleArgs::F2(def::Int(1)));
}
source

pub fn parse(&self, input: &str) -> Result<Value, Error>

Examples found in repository?
examples/test-expand.rs (line 99)
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for ModuleArgs {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
pub struct ModuleSubObj {
    pub global: def::Option<def::Bool>,
    pub imports: def::Array<def::Ident>,
    pub sub: def::Option<Sub>,
}
#[automatically_derived]
impl ::core::fmt::Debug for ModuleSubObj {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field3_finish(f, "ModuleSubObj", "global", &self.global, "imports", &self.imports, "sub", &&self.sub)
    }
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for ModuleSubObj {}
#[automatically_derived]
impl ::core::cmp::PartialEq for ModuleSubObj {
    #[inline]
    fn eq(&self, other: &ModuleSubObj) -> bool {
        self.global == other.global && self.imports == other.imports && self.sub == other.sub
    }
}
impl TryFrom<&syn_args::Value> for ModuleSubObj {
    type Error = syn::Error;
    fn try_from(v: &syn_args::Value) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(_) = v {
            return Ok(ModuleSubObj {
                global: syn_args::Transform::new(v, "global").try_into()?,
                imports: syn_args::Transform::new(v, "imports").try_into()?,
                sub: syn_args::Transform::new(v, "sub").try_into()?,
            });
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Invalid args"))
    }
}
impl TryFrom<syn_args::Value> for ModuleSubObj {
    type Error = syn::Error;
    fn try_from(v: syn_args::Value) -> Result<Self, Self::Error> {
        ModuleSubObj::try_from(&v)
    }
}
impl syn_args::ArgsParse for ModuleSubObj {
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for ModuleSubObj {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
pub struct Sub {
    pub value: def::Bool,
}
#[automatically_derived]
impl ::core::fmt::Debug for Sub {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field1_finish(f, "Sub", "value", &&self.value)
    }
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for Sub {}
#[automatically_derived]
impl ::core::cmp::PartialEq for Sub {
    #[inline]
    fn eq(&self, other: &Sub) -> bool {
        self.value == other.value
    }
}
impl TryFrom<&syn_args::Value> for Sub {
    type Error = syn::Error;
    fn try_from(v: &syn_args::Value) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(_) = v {
            return Ok(Sub { value: syn_args::Transform::new(v, "value").try_into()? });
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Invalid args"))
    }
}
impl TryFrom<syn_args::Value> for Sub {
    type Error = syn::Error;
    fn try_from(v: syn_args::Value) -> Result<Self, Self::Error> {
        Sub::try_from(&v)
    }
}
impl syn_args::ArgsParse for Sub {
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for Sub {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
pub struct SubWrap {
    pub s1: Sub,
    pub s2: Sub,
}
#[automatically_derived]
impl ::core::fmt::Debug for SubWrap {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        ::core::fmt::Formatter::debug_struct_field2_finish(f, "SubWrap", "s1", &self.s1, "s2", &&self.s2)
    }
}
#[automatically_derived]
impl ::core::marker::StructuralPartialEq for SubWrap {}
#[automatically_derived]
impl ::core::cmp::PartialEq for SubWrap {
    #[inline]
    fn eq(&self, other: &SubWrap) -> bool {
        self.s1 == other.s1 && self.s2 == other.s2
    }
}
impl TryFrom<&syn_args::Value> for SubWrap {
    type Error = syn::Error;
    fn try_from(v: &syn_args::Value) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(_) = v {
            return Ok(SubWrap { s1: syn_args::Transform::new(v, "s1").try_into()?, s2: syn_args::Transform::new(v, "s2").try_into()? });
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Invalid args"))
    }
}
impl TryFrom<syn_args::Value> for SubWrap {
    type Error = syn::Error;
    fn try_from(v: syn_args::Value) -> Result<Self, Self::Error> {
        SubWrap::try_from(&v)
    }
}
impl syn_args::ArgsParse for SubWrap {
    fn parse(input: &str) -> Result<Self, syn::Error> {
        syn_args::Formal::new().parse(input)?.try_into()
    }
}
impl TryFrom<syn_args::Transform<'_>> for SubWrap {
    type Error = syn::Error;
    fn try_from(value: syn_args::Transform) -> Result<Self, Self::Error> {
        if let syn_args::Value::Object(obj) = value.value {
            if let Some(v) = obj.get(value.key) {
                return Ok(v.try_into()?);
            }
        }
        Err(Self::Error::new(proc_macro2::Span::call_site(), "Expected SubWrap"))
    }
}
fn test_formal_f1() {
    let f = Formal::new();
    let args = f.parse("F(1, 3)").unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", args));
    };
    let res = ModuleArgs::try_from(&args).unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", res));
    };
    match (&res, &ModuleArgs::F1(def::Int(1), def::Int(3))) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val, &*right_val, ::core::option::Option::None);
            }
        }
    };
}
fn test_formal_f2() {
    let f = Formal::new();
    let args = f.parse("F(1)").unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", args));
    };
    let res = ModuleArgs::try_from(&args).unwrap();
    {
        ::std::io::_print(format_args!("{0:?}\n", res));
    };
    match (&res, &ModuleArgs::F2(def::Int(1))) {
        (left_val, right_val) => {
            if !(*left_val == *right_val) {
                let kind = ::core::panicking::AssertKind::Eq;
                ::core::panicking::assert_failed(kind, &*left_val, &*right_val, ::core::option::Option::None);
            }
        }
    };
}
More examples
Hide additional examples
examples/test.rs (line 36)
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
fn test_formal_f1() {
    let f = Formal::new();

    // fm.parse("F(Object{ a: Int, b: Optional(Int) }, Array(Int))");
    let args = f.parse("F(1, 3)").unwrap();
    // let args = f.parse("F(1)").unwrap();
    // let args = f.parse("F(Hello)").unwrap();
    println!("{:?}", args);

    let res = ModuleArgs::try_from(&args).unwrap();
    println!("{:?}", res);

    assert_eq!(res, ModuleArgs::F1(def::Int(1), def::Int(3)));
}

fn test_formal_f2() {
    let f = Formal::new();

    let args = f.parse("F(1)").unwrap();
    // let args = f.parse("F(Hello)").unwrap();
    println!("{:?}", args);

    let res = ModuleArgs::try_from(&args).unwrap();
    println!("{:?}", res);

    assert_eq!(res, ModuleArgs::F2(def::Int(1)));
}

Trait Implementations§

source§

impl Default for Formal

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Formal

§

impl RefUnwindSafe for Formal

§

impl Send for Formal

§

impl Sync for Formal

§

impl Unpin for Formal

§

impl UnwindSafe for Formal

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.