Merge pull request #114 from media-io/update

Update
This commit is contained in:
Marc-Antoine ARNAUD 2021-05-31 10:41:18 +02:00 committed by GitHub
commit 4f78a2f701
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 69 additions and 72 deletions

View File

@ -16,6 +16,9 @@ rust:
- 1.47.0
- 1.48.0
- 1.49.0
- 1.50.0
- 1.51.0
- 1.52.0
- stable
- beta
- nightly

View File

@ -44,8 +44,7 @@ impl YaSerdeAttribute {
for attr in attrs.iter().filter(|a| a.path.is_ident("yaserde")) {
let mut attr_iter = attr.clone().tokens.into_iter();
if let Some(token) = attr_iter.next() {
if let TokenTree::Group(group) = token {
if let Some(TokenTree::Group(group)) = attr_iter.next() {
if group.delimiter() == Delimiter::Parenthesis {
let mut attr_iter = group.stream().into_iter();
@ -94,7 +93,6 @@ impl YaSerdeAttribute {
}
}
}
}
YaSerdeAttribute {
attribute,
@ -147,7 +145,7 @@ impl YaSerdeAttribute {
None
}
})
.filter_map(|x| x)
.flatten()
.collect();
quote!(

View File

@ -240,21 +240,17 @@ impl From<&syn::Field> for Field {
impl From<&syn::PathSegment> for Field {
fn from(path_segment: &syn::PathSegment) -> Self {
if let syn::PathArguments::AngleBracketed(ref args) = path_segment.arguments {
if let Some(tt) = args.args.first() {
if let syn::GenericArgument::Type(ref argument) = *tt {
if let Path(ref path) = *argument {
if let Some(syn::GenericArgument::Type(Path(ref path))) = args.args.first() {
return Field::from(&path.path);
}
}
}
}
unimplemented!()
}
}
impl Into<proc_macro2::TokenStream> for Field {
fn into(self) -> proc_macro2::TokenStream {
match self {
impl From<Field> for proc_macro2::TokenStream {
fn from(field: Field) -> proc_macro2::TokenStream {
match field {
Field::FieldString => quote! { ::std::string::String },
Field::FieldBool => quote! { bool },
Field::FieldI8 => quote! { i8 },
@ -267,14 +263,14 @@ impl Into<proc_macro2::TokenStream> for Field {
Field::FieldU64 => quote! { u64 },
Field::FieldF32 => quote! { f32 },
Field::FieldF64 => quote! { f64 },
_ => panic!("Not a simple type: {:?}", self),
_ => panic!("Not a simple type: {:?}", field),
}
}
}
impl Into<String> for &Field {
fn into(self) -> String {
match self {
impl From<&Field> for String {
fn from(field: &Field) -> String {
match field {
Field::FieldString => "str".to_string(),
Field::FieldBool => "bool".to_string(),
Field::FieldI8 => "i8".to_string(),
@ -287,7 +283,7 @@ impl Into<String> for &Field {
Field::FieldU64 => "u64".to_string(),
Field::FieldF32 => "f32".to_string(),
Field::FieldF64 => "f64".to_string(),
_ => panic!("Not a simple type: {:?}", self),
_ => panic!("Not a simple type: {:?}", field),
}
}
}

View File

@ -20,7 +20,7 @@ pub fn parse(
.variants
.iter()
.map(|variant| parse_variant(variant, name))
.filter_map(|f| f)
.flatten()
.collect();
let flatten = root_attributes.flatten;
@ -302,6 +302,6 @@ fn build_unnamed_visitor_calls(
simple_type => call_simple_type_visitor(simple_type, set_val),
}
})
.filter_map(|f| f)
.flatten()
.collect()
}

View File

@ -57,7 +57,7 @@ pub fn parse(
build_default_value(&field, Some(type_token), value_builder)
}
})
.filter_map(|x| x)
.flatten()
.collect();
let field_visitors: TokenStream = data_struct
@ -94,7 +94,7 @@ pub fn parse(
let simple_type_visitor = |simple_type: Field| {
let visitor = simple_type.get_simple_type_visitor();
let visitor_label = field.get_visitor_ident(None);
let field_type: TokenStream = simple_type.into();
let field_type = TokenStream::from(simple_type);
let map_if_bool = if field_type.to_string() == "bool" {
quote!(match v {
@ -137,7 +137,7 @@ pub fn parse(
simple_type => simple_type_visitor(simple_type),
}
})
.filter_map(|x| x)
.flatten()
.collect();
let call_visitors: TokenStream = data_struct
@ -167,7 +167,7 @@ pub fn parse(
let visit_simple = |simple_type: Field, action: TokenStream| {
let field_visitor = simple_type.get_simple_type_visitor();
let field_type: TokenStream = simple_type.into();
let field_type = TokenStream::from(simple_type);
build_call_visitor(
&field_type,
&field_visitor,
@ -192,7 +192,7 @@ pub fn parse(
simple_type => visit_simple(simple_type, quote! { = value }),
}
})
.filter_map(|x| x)
.flatten()
.collect();
let call_flatten_visitors: TokenStream = data_struct
@ -216,7 +216,7 @@ pub fn parse(
field_type => unimplemented!(r#""flatten" is not implemented for {:?}"#, field_type),
}
})
.filter_map(|x| x)
.flatten()
.collect();
let attributes_loading: TokenStream = data_struct
@ -283,7 +283,7 @@ pub fn parse(
simple_type => visit_simple(simple_type, quote! { = value }),
}
})
.filter_map(|x| x)
.flatten()
.collect();
let set_text: TokenStream = data_struct
@ -311,12 +311,12 @@ pub fn parse(
},
Field::FieldStruct { .. } | Field::FieldVec { .. } => None,
simple_type => {
let type_token: TokenStream = simple_type.into();
let type_token = TokenStream::from(simple_type);
set_text(&quote! { #type_token::from_str(text_content).unwrap() })
}
}
})
.filter_map(|x| x)
.flatten()
.collect();
let struct_builder: TokenStream = data_struct

View File

@ -124,7 +124,7 @@ fn inner_enum_inspector(
Field::FieldOption { .. } => None,
}
})
.filter_map(|x| x)
.flatten()
.collect();
Some(quote! {
@ -211,7 +211,7 @@ fn inner_enum_inspector(
_simple_type => Some(match_field(&write_simple_type)),
}
})
.filter_map(|x| x)
.flatten()
.collect();
Some(quote! {
@ -222,6 +222,6 @@ fn inner_enum_inspector(
}
}
})
.filter_map(|x| x)
.flatten()
.collect()
}

View File

@ -324,7 +324,7 @@ pub fn serialize(
},
}
})
.filter_map(|x| x)
.flatten()
.collect();
implement_serializer(

View File

@ -18,6 +18,6 @@ pub fn generate_namespaces_definition(attributes: &YaSerdeAttribute) -> TokenStr
.ns(#prefix, #namespace)
))
})
.filter_map(|x| x)
.flatten()
.collect()
}