Enforce std String in macros to avoid collisions

This commit is contained in:
marcelbuesing
2020-07-27 13:48:36 +02:00
parent 460c8320c6
commit 701b92a2a4
8 changed files with 56 additions and 49 deletions

View File

@@ -254,7 +254,7 @@ impl From<&syn::PathSegment> for Field {
impl Into<proc_macro2::TokenStream> for Field {
fn into(self) -> proc_macro2::TokenStream {
match self {
Field::FieldString => quote! {String},
Field::FieldString => quote! {std::string::String},
Field::FieldBool => quote! {bool},
Field::FieldI8 => quote! {i8},
Field::FieldU8 => quote! {u8},
@@ -272,7 +272,7 @@ impl Into<proc_macro2::TokenStream> for Field {
}
impl Into<String> for &Field {
fn into(self) -> String {
fn into(self) -> std::string::String {
match self {
Field::FieldString => "str".to_string(),
Field::FieldBool => "bool".to_string(),
@@ -293,7 +293,7 @@ impl Into<String> for &Field {
impl fmt::Display for Field {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let string_representation: String = self.into();
let string_representation: std::string::String = self.into();
write!(f, "{}", string_representation)
}
}

View File

@@ -33,12 +33,12 @@ pub fn parse(
impl YaDeserialize for #name {
#[allow(unused_variables)]
fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> Result<Self, String> {
fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> Result<Self, std::string::String> {
let (named_element, enum_namespace) =
if let XmlEvent::StartElement{name, ..} = reader.peek()?.to_owned() {
(name.local_name.to_owned(), name.namespace.clone())
} else {
(String::from(#root), None)
(std::string::String::from(#root), None)
};
let start_depth = reader.depth();
@@ -161,7 +161,7 @@ fn build_unnamed_field_visitors(fields: &syn::FieldsUnnamed) -> TokenStream {
impl<'de> Visitor<'de> for #visitor_label {
type Value = #field_type;
fn #visitor(self, v: &str) -> Result<Self::Value, String> {
fn #visitor(self, v: &str) -> Result<Self::Value, std::string::String> {
#fn_body
}
}
@@ -181,7 +181,7 @@ fn build_unnamed_field_visitors(fields: &syn::FieldsUnnamed) -> TokenStream {
match field.get_type() {
Field::FieldStruct { struct_name } => {
let struct_id: String = struct_name
let struct_id: std::string::String = struct_name
.segments
.iter()
.map(|s| s.ident.to_string())
@@ -192,7 +192,7 @@ fn build_unnamed_field_visitors(fields: &syn::FieldsUnnamed) -> TokenStream {
&quote! { #struct_name },
&quote! {
let content = "<".to_string() + #struct_id + ">" + v + "</" + #struct_id + ">";
let value : Result<#struct_name, String> = yaserde::de::from_str(&content);
let value : Result<#struct_name, std::string::String> = yaserde::de::from_str(&content);
value
},
)
@@ -267,7 +267,7 @@ fn build_unnamed_visitor_calls(
match enum_value {
Some(ref mut v) => match v {
#variant_name(ref mut v) => v.push(value),
_ => return Err(String::from("Got sequence of different types"))
_ => return Err(std::string::String::from("Got sequence of different types"))
}
None => {
enum_value = Some(#variant_name(vec![value]));

View File

@@ -57,7 +57,7 @@ pub fn parse(
.map(|field| YaSerdeField::new(field.clone()))
.map(|field| {
let struct_visitor = |struct_name: syn::Path| {
let struct_id: String = struct_name
let struct_id: std::string::String = struct_name
.segments
.iter()
.map(|s| s.ident.to_string())
@@ -71,9 +71,9 @@ pub fn parse(
impl<'de> Visitor<'de> for #visitor_label {
type Value = #struct_name;
fn visit_str(self, v: &str) -> Result<Self::Value, String> {
fn visit_str(self, v: &str) -> Result<Self::Value, std::string::String> {
let content = "<".to_string() + #struct_id + ">" + v + "</" + #struct_id + ">";
let value : Result<#struct_name, String> = yaserde::de::from_str(&content);
let value : Result<#struct_name, std::string::String> = yaserde::de::from_str(&content);
value
}
}
@@ -91,7 +91,7 @@ pub fn parse(
impl<'de> Visitor<'de> for #visitor_label {
type Value = #field_type;
fn #visitor(self, v: &str) -> Result<Self::Value, String> {
fn #visitor(self, v: &str) -> Result<Self::Value, std::string::String> {
Ok(#field_type::from_str(v).unwrap())
}
}
@@ -315,12 +315,12 @@ pub fn parse(
impl YaDeserialize for #name {
#[allow(unused_variables)]
fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> Result<Self, String> {
fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> Result<Self, std::string::String> {
let (named_element, struct_namespace) =
if let XmlEvent::StartElement{name, ..} = reader.peek()?.to_owned() {
(name.local_name.to_owned(), name.namespace.clone())
} else {
(String::from(#root), None)
(std::string::String::from(#root), None)
};
let start_depth = reader.depth();
debug!("Struct {} @ {}: start to parse {:?}", stringify!(#name), start_depth,
@@ -476,7 +476,7 @@ fn build_code_for_unused_xml_events(
}),
Some(quote! {
if writer.is_some() {
let unused_xml_elements = String::from_utf8(buf).unwrap();
let unused_xml_elements = std::string::String::from_utf8(buf).unwrap();
#call_flatten_visitors
}
}),

View File

@@ -62,7 +62,7 @@ pub fn serialize(
| Field::FieldU64
| Field::FieldF32
| Field::FieldF64 => field.ser_wrap_default_attribute(
Some(quote!(self.#label.map_or_else(|| String::new(), |v| v.to_string()))),
Some(quote!(self.#label.map_or_else(|| std::string::String::new(), |v| v.to_string()))),
quote!({
if let Some(ref value) = self.#label {
struct_start_event.attr(#label_name, &yaserde_inner)
@@ -89,7 +89,7 @@ pub fn serialize(
Field::FieldStruct { .. } => field.ser_wrap_default_attribute(
Some(quote!(self.#label
.as_ref()
.map_or_else(|| Ok(String::new()), |v| yaserde::ser::to_string_content(v))?)),
.map_or_else(|| Ok(std::string::String::new()), |v| yaserde::ser::to_string_content(v))?)),
quote!({
if let Some(ref yaserde_struct) = self.#label {
struct_start_event.attr(#label_name, &yaserde_inner)

View File

@@ -19,7 +19,7 @@ pub fn implement_serializer(
impl YaSerialize for #name {
#[allow(unused_variables)]
fn serialize<W: Write>(&self, writer: &mut yaserde::ser::Serializer<W>)
-> Result<(), String> {
-> Result<(), std::string::String> {
let skip = writer.skip_start_end();
if !#flatten && !skip {
@@ -61,7 +61,7 @@ pub fn implement_serializer(
Ok(())
}
fn serialize_attributes(&self, mut source_attributes: Vec<xml::attribute::OwnedAttribute>, mut source_namespace: xml::namespace::Namespace) -> Result<(Vec<xml::attribute::OwnedAttribute>, xml::namespace::Namespace), String> {
fn serialize_attributes(&self, mut source_attributes: Vec<xml::attribute::OwnedAttribute>, mut source_namespace: xml::namespace::Namespace) -> Result<(Vec<xml::attribute::OwnedAttribute>, xml::namespace::Namespace), std::string::String> {
let mut child_attributes : Vec<xml::attribute::OwnedAttribute> = vec![];
let mut child_attributes_namespace = xml::namespace::Namespace::empty();