commit
4f78a2f701
@ -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
|
||||
|
||||
@ -44,51 +44,49 @@ 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 group.delimiter() == Delimiter::Parenthesis {
|
||||
let mut attr_iter = group.stream().into_iter();
|
||||
if let Some(TokenTree::Group(group)) = attr_iter.next() {
|
||||
if group.delimiter() == Delimiter::Parenthesis {
|
||||
let mut attr_iter = group.stream().into_iter();
|
||||
|
||||
while let Some(item) = attr_iter.next() {
|
||||
if let TokenTree::Ident(ident) = item {
|
||||
match ident.to_string().as_str() {
|
||||
"attribute" => {
|
||||
attribute = true;
|
||||
}
|
||||
"default" => {
|
||||
default = get_value(&mut attr_iter);
|
||||
}
|
||||
"default_namespace" => {
|
||||
default_namespace = get_value(&mut attr_iter);
|
||||
}
|
||||
"flatten" => {
|
||||
flatten = true;
|
||||
}
|
||||
"namespace" => {
|
||||
if let Some(namespace) = get_value(&mut attr_iter) {
|
||||
let splitted: Vec<&str> = namespace.split(": ").collect();
|
||||
if splitted.len() == 2 {
|
||||
namespaces.insert(splitted[0].to_owned(), splitted[1].to_owned());
|
||||
}
|
||||
if splitted.len() == 1 {
|
||||
namespaces.insert("".to_owned(), splitted[0].to_owned());
|
||||
}
|
||||
while let Some(item) = attr_iter.next() {
|
||||
if let TokenTree::Ident(ident) = item {
|
||||
match ident.to_string().as_str() {
|
||||
"attribute" => {
|
||||
attribute = true;
|
||||
}
|
||||
"default" => {
|
||||
default = get_value(&mut attr_iter);
|
||||
}
|
||||
"default_namespace" => {
|
||||
default_namespace = get_value(&mut attr_iter);
|
||||
}
|
||||
"flatten" => {
|
||||
flatten = true;
|
||||
}
|
||||
"namespace" => {
|
||||
if let Some(namespace) = get_value(&mut attr_iter) {
|
||||
let splitted: Vec<&str> = namespace.split(": ").collect();
|
||||
if splitted.len() == 2 {
|
||||
namespaces.insert(splitted[0].to_owned(), splitted[1].to_owned());
|
||||
}
|
||||
if splitted.len() == 1 {
|
||||
namespaces.insert("".to_owned(), splitted[0].to_owned());
|
||||
}
|
||||
}
|
||||
"prefix" => {
|
||||
prefix = get_value(&mut attr_iter);
|
||||
}
|
||||
"rename" => {
|
||||
rename = get_value(&mut attr_iter);
|
||||
}
|
||||
"skip_serializing_if" => {
|
||||
skip_serializing_if = get_value(&mut attr_iter);
|
||||
}
|
||||
"text" => {
|
||||
text = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
"prefix" => {
|
||||
prefix = get_value(&mut attr_iter);
|
||||
}
|
||||
"rename" => {
|
||||
rename = get_value(&mut attr_iter);
|
||||
}
|
||||
"skip_serializing_if" => {
|
||||
skip_serializing_if = get_value(&mut attr_iter);
|
||||
}
|
||||
"text" => {
|
||||
text = true;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,7 +145,7 @@ impl YaSerdeAttribute {
|
||||
None
|
||||
}
|
||||
})
|
||||
.filter_map(|x| x)
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
quote!(
|
||||
|
||||
@ -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 {
|
||||
return Field::from(&path.path);
|
||||
}
|
||||
}
|
||||
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),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -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("e! { #type_token::from_str(text_content).unwrap() })
|
||||
}
|
||||
}
|
||||
})
|
||||
.filter_map(|x| x)
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
let struct_builder: TokenStream = data_struct
|
||||
|
||||
@ -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()
|
||||
}
|
||||
|
||||
@ -324,7 +324,7 @@ pub fn serialize(
|
||||
},
|
||||
}
|
||||
})
|
||||
.filter_map(|x| x)
|
||||
.flatten()
|
||||
.collect();
|
||||
|
||||
implement_serializer(
|
||||
|
||||
@ -18,6 +18,6 @@ pub fn generate_namespaces_definition(attributes: &YaSerdeAttribute) -> TokenStr
|
||||
.ns(#prefix, #namespace)
|
||||
))
|
||||
})
|
||||
.filter_map(|x| x)
|
||||
.flatten()
|
||||
.collect()
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user