Drop unnecessary qualification of String outside of generated code
This commit is contained in:
parent
d3ee4112e3
commit
c455f12d23
@ -19,13 +19,12 @@ pub mod ser;
|
||||
|
||||
/// A **data structure** that can be deserialized from any data format supported by YaSerDe.
|
||||
pub trait YaDeserialize: Sized {
|
||||
fn deserialize<R: Read>(reader: &mut de::Deserializer<R>) -> Result<Self, std::string::String>;
|
||||
fn deserialize<R: Read>(reader: &mut de::Deserializer<R>) -> Result<Self, String>;
|
||||
}
|
||||
|
||||
/// A **data structure** that can be serialized into any data format supported by YaSerDe.
|
||||
pub trait YaSerialize: Sized {
|
||||
fn serialize<W: Write>(&self, writer: &mut ser::Serializer<W>)
|
||||
-> Result<(), std::string::String>;
|
||||
fn serialize<W: Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String>;
|
||||
|
||||
fn serialize_attributes(
|
||||
&self,
|
||||
@ -36,7 +35,7 @@ pub trait YaSerialize: Sized {
|
||||
Vec<xml::attribute::OwnedAttribute>,
|
||||
xml::namespace::Namespace,
|
||||
),
|
||||
std::string::String,
|
||||
String,
|
||||
>;
|
||||
}
|
||||
|
||||
@ -45,51 +44,51 @@ pub trait Visitor<'de>: Sized {
|
||||
/// The value produced by this visitor.
|
||||
type Value;
|
||||
|
||||
fn visit_bool(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_bool(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected bool {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_i8(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_i8(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected i8 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_u8(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_u8(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected u8 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_i16(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_i16(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected i16 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_u16(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_u16(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected u16 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_i32(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_i32(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected i32 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_u32(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_u32(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected u32 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_i64(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_i64(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected i64 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_u64(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_u64(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected u64 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_f32(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_f32(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected f32 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_f64(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_f64(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected f64 {:?}", v))
|
||||
}
|
||||
|
||||
fn visit_str(self, v: &str) -> Result<Self::Value, std::string::String> {
|
||||
fn visit_str(self, v: &str) -> Result<Self::Value, String> {
|
||||
Err(format!("Unexpected str {:?}", v))
|
||||
}
|
||||
}
|
||||
@ -97,10 +96,7 @@ pub trait Visitor<'de>: Sized {
|
||||
macro_rules! serialize_type {
|
||||
($type:ty) => {
|
||||
impl YaSerialize for $type {
|
||||
fn serialize<W: Write>(
|
||||
&self,
|
||||
writer: &mut ser::Serializer<W>,
|
||||
) -> Result<(), std::string::String> {
|
||||
fn serialize<W: Write>(&self, writer: &mut ser::Serializer<W>) -> Result<(), String> {
|
||||
let content = format!("{}", self);
|
||||
let event = XmlEvent::characters(&content);
|
||||
let _ret = writer.write(event);
|
||||
@ -116,7 +112,7 @@ macro_rules! serialize_type {
|
||||
Vec<xml::attribute::OwnedAttribute>,
|
||||
xml::namespace::Namespace,
|
||||
),
|
||||
std::string::String,
|
||||
String,
|
||||
> {
|
||||
Ok((attributes, namespace))
|
||||
}
|
||||
@ -182,9 +178,9 @@ mod testing {
|
||||
let model = Data { item: $value };
|
||||
|
||||
let content = if let Some(str_value) = $content {
|
||||
std::string::String::from("<data><item>") + str_value + "</item></data>"
|
||||
String::from("<data><item>") + str_value + "</item></data>"
|
||||
} else {
|
||||
std::string::String::from("<data />")
|
||||
String::from("<data />")
|
||||
};
|
||||
|
||||
serialize_and_validate!(model, content);
|
||||
@ -218,7 +214,7 @@ mod testing {
|
||||
macro_rules! deserialize_and_validate {
|
||||
($content: expr, $model: expr, $struct: tt) => {
|
||||
log::debug!("deserialize_and_validate @ {}:{}", file!(), line!());
|
||||
let loaded: Result<$struct, std::string::String> = yaserde::de::from_str($content);
|
||||
let loaded: Result<$struct, String> = yaserde::de::from_str($content);
|
||||
assert_eq!(loaded, Ok($model));
|
||||
};
|
||||
}
|
||||
@ -227,17 +223,16 @@ mod testing {
|
||||
macro_rules! serialize_and_validate {
|
||||
($model: expr, $content: expr) => {
|
||||
log::debug!("serialize_and_validate @ {}:{}", file!(), line!());
|
||||
let data: Result<std::string::String, std::string::String> = yaserde::ser::to_string(&$model);
|
||||
let data: Result<String, String> = yaserde::ser::to_string(&$model);
|
||||
|
||||
let content =
|
||||
std::string::String::from(r#"<?xml version="1.0" encoding="utf-8"?>"#) + &$content;
|
||||
let content = String::from(r#"<?xml version="1.0" encoding="utf-8"?>"#) + &$content;
|
||||
assert_eq!(
|
||||
data,
|
||||
Ok(
|
||||
std::string::String::from(content)
|
||||
String::from(content)
|
||||
.split("\n")
|
||||
.map(|s| s.trim())
|
||||
.collect::<std::string::String>()
|
||||
.collect::<String>()
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
@ -11,14 +11,14 @@ pub fn to_string<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||
let buf = Cursor::new(Vec::new());
|
||||
let cursor = serialize_with_writer(model, buf, &Config::default())?;
|
||||
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
|
||||
Ok(std::string::String::from(data))
|
||||
Ok(String::from(data))
|
||||
}
|
||||
|
||||
pub fn to_string_with_config<T: YaSerialize>(model: &T, config: &Config) -> Result<String, String> {
|
||||
let buf = Cursor::new(Vec::new());
|
||||
let cursor = serialize_with_writer(model, buf, config)?;
|
||||
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
|
||||
Ok(std::string::String::from(data))
|
||||
Ok(String::from(data))
|
||||
}
|
||||
|
||||
pub fn serialize_with_writer<W: Write, T: YaSerialize>(
|
||||
@ -37,7 +37,7 @@ pub fn to_string_content<T: YaSerialize>(model: &T) -> Result<String, String> {
|
||||
let buf = Cursor::new(Vec::new());
|
||||
let cursor = serialize_with_writer_content(model, buf)?;
|
||||
let data = str::from_utf8(cursor.get_ref()).expect("Found invalid UTF-8");
|
||||
Ok(std::string::String::from(data))
|
||||
Ok(String::from(data))
|
||||
}
|
||||
|
||||
pub fn serialize_with_writer_content<W: Write, T: YaSerialize>(
|
||||
|
||||
@ -15,7 +15,7 @@ fn init() {
|
||||
macro_rules! convert_and_validate {
|
||||
($content: expr, $struct: tt, $model: expr) => {
|
||||
debug!("convert_and_validate @ {}:{}", file!(), line!());
|
||||
let loaded: Result<$struct, std::string::String> = from_str($content);
|
||||
let loaded: Result<$struct, String> = from_str($content);
|
||||
assert_eq!(loaded, Ok($model));
|
||||
};
|
||||
}
|
||||
@ -118,15 +118,15 @@ fn de_multiple_segments() {
|
||||
#[derive(YaDeserialize, PartialEq, Debug, Default)]
|
||||
pub struct Page {
|
||||
pub number: i32,
|
||||
pub text: std::string::String,
|
||||
pub text: String,
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(YaDeserialize, PartialEq, Debug)]
|
||||
#[yaserde(root = "book")]
|
||||
pub struct Book {
|
||||
author: std::string::String,
|
||||
title: std::string::String,
|
||||
author: String,
|
||||
title: String,
|
||||
page: other_mod::Page,
|
||||
}
|
||||
|
||||
@ -277,7 +277,7 @@ fn de_attributes_custom_deserializer() {
|
||||
#[derive(Default, YaDeserialize, PartialEq, Debug)]
|
||||
pub struct Struct {
|
||||
#[yaserde(attribute)]
|
||||
attr_option_string: Option<std::string::String>,
|
||||
attr_option_string: Option<String>,
|
||||
#[yaserde(attribute)]
|
||||
attr_option_struct: Option<other_mod::Attributes>,
|
||||
}
|
||||
@ -326,7 +326,7 @@ fn de_attributes_complex() {
|
||||
#[derive(Default, YaDeserialize, PartialEq, Debug)]
|
||||
pub struct Struct {
|
||||
#[yaserde(attribute)]
|
||||
attr_option_string: Option<std::string::String>,
|
||||
attr_option_string: Option<String>,
|
||||
#[yaserde(attribute)]
|
||||
attr_option_enum: Option<other_mod::AttrEnum>,
|
||||
}
|
||||
@ -559,7 +559,7 @@ fn de_complex_enum() {
|
||||
pub enum Color {
|
||||
White,
|
||||
Black(String),
|
||||
Orange(std::string::String),
|
||||
Orange(String),
|
||||
Red(i32),
|
||||
Green(OtherStruct),
|
||||
Yellow(Option<String>),
|
||||
@ -801,9 +801,7 @@ fn de_custom() {
|
||||
}
|
||||
|
||||
impl YaDeserialize for Day {
|
||||
fn deserialize<R: Read>(
|
||||
reader: &mut yaserde::de::Deserializer<R>,
|
||||
) -> Result<Self, std::string::String> {
|
||||
fn deserialize<R: Read>(reader: &mut yaserde::de::Deserializer<R>) -> Result<Self, String> {
|
||||
use std::str::FromStr;
|
||||
|
||||
if let xml::reader::XmlEvent::StartElement { name, .. } = reader.peek()?.to_owned() {
|
||||
|
||||
@ -165,7 +165,7 @@ fn unnamed_enum() {
|
||||
pub enum Enum {
|
||||
Simple,
|
||||
Field(String),
|
||||
FullPath(std::string::String),
|
||||
FullPath(String),
|
||||
Integer(i32),
|
||||
UserStruct(OtherStruct),
|
||||
OptionString(Option<String>),
|
||||
|
||||
@ -195,7 +195,7 @@ fn ser_attributes_complex() {
|
||||
#[derive(YaSerialize, PartialEq, Debug)]
|
||||
pub struct Struct {
|
||||
#[yaserde(attribute)]
|
||||
attr_option_string: Option<std::string::String>,
|
||||
attr_option_string: Option<String>,
|
||||
#[yaserde(attribute)]
|
||||
attr_option_enum: Option<other_mod::AttrEnum>,
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ impl Into<proc_macro2::TokenStream> for Field {
|
||||
}
|
||||
|
||||
impl Into<String> for &Field {
|
||||
fn into(self) -> std::string::String {
|
||||
fn into(self) -> String {
|
||||
match self {
|
||||
Field::FieldString => "str".to_string(),
|
||||
Field::FieldBool => "bool".to_string(),
|
||||
@ -294,7 +294,7 @@ impl Into<String> for &Field {
|
||||
|
||||
impl fmt::Display for Field {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
let string_representation: std::string::String = self.into();
|
||||
let string_representation: String = self.into();
|
||||
write!(f, "{}", string_representation)
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,7 +182,7 @@ fn build_unnamed_field_visitors(fields: &syn::FieldsUnnamed) -> TokenStream {
|
||||
|
||||
match field.get_type() {
|
||||
Field::FieldStruct { struct_name } => {
|
||||
let struct_id: std::string::String = struct_name
|
||||
let struct_id: String = struct_name
|
||||
.segments
|
||||
.iter()
|
||||
.map(|s| s.ident.to_string())
|
||||
|
||||
@ -66,7 +66,7 @@ pub fn parse(
|
||||
.map(|field| YaSerdeField::new(field.clone()))
|
||||
.map(|field| {
|
||||
let struct_visitor = |struct_name: syn::Path| {
|
||||
let struct_id: std::string::String = struct_name
|
||||
let struct_id: String = struct_name
|
||||
.segments
|
||||
.iter()
|
||||
.map(|s| s.ident.to_string())
|
||||
|
||||
Loading…
Reference in New Issue
Block a user