Struct syn_args::Transform

source ·
pub struct Transform<'a> {
    pub value: &'a Value,
    pub key: &'a str,
}

Fields§

§value: &'a Value§key: &'a str

Implementations§

source§

impl<'a> Transform<'a>

source

pub fn new(value: &'a Value, key: &'a str) -> Self

Examples found in repository?
examples/test-expand.rs (line 139)
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
    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"))
    }

Trait Implementations§

source§

impl<'a, T> TryFrom<Transform<'a>> for Option<T>
where T: TryFrom<&'a Value, Error = Error>,

§

type Error = Error

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

fn try_from(value: Transform<'a>) -> Result<Self, Self::Error>

Performs the conversion.
source§

impl<'a, T> TryInto<Array<T>> for Transform<'a>
where T: TryFrom<&'a Value, Error = Error>,

§

type Error = Error

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

fn try_into(self) -> Result<Array<T>, Self::Error>

Performs the conversion.
source§

impl<'a> TryInto<Bool> for Transform<'a>

§

type Error = Error

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

fn try_into(self) -> Result<Bool, Self::Error>

Performs the conversion.
source§

impl<'a> TryInto<Float> for Transform<'a>

§

type Error = Error

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

fn try_into(self) -> Result<Float, Self::Error>

Performs the conversion.
source§

impl<'a> TryInto<Ident> for Transform<'a>

§

type Error = Error

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

fn try_into(self) -> Result<Ident, Self::Error>

Performs the conversion.
source§

impl<'a> TryInto<Int> for Transform<'a>

§

type Error = Error

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

fn try_into(self) -> Result<Int, Self::Error>

Performs the conversion.
source§

impl<'a> TryInto<Null> for Transform<'a>

§

type Error = Error

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

fn try_into(self) -> Result<Null, Self::Error>

Performs the conversion.
source§

impl<'a, T> TryInto<Object<T>> for Transform<'a>
where T: TryFrom<&'a Value, Error = Error>,

§

type Error = Error

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

fn try_into(self) -> Result<Object<T>, Self::Error>

Performs the conversion.
source§

impl<'a> TryInto<String> for Transform<'a>

§

type Error = Error

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

fn try_into(self) -> Result<String, Self::Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<'a> Freeze for Transform<'a>

§

impl<'a> RefUnwindSafe for Transform<'a>

§

impl<'a> Send for Transform<'a>

§

impl<'a> Sync for Transform<'a>

§

impl<'a> Unpin for Transform<'a>

§

impl<'a> UnwindSafe for Transform<'a>

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.