diff --git a/instant-xml-macros/src/lib.rs b/instant-xml-macros/src/lib.rs index eb6817c..2411889 100644 --- a/instant-xml-macros/src/lib.rs +++ b/instant-xml-macros/src/lib.rs @@ -136,10 +136,7 @@ pub fn to_xml(input: proc_macro::TokenStream) -> proc_macro::TokenStream { proc_macro::TokenStream::from(quote!( impl #generics ToXml for #ident #generics { - fn serialize(&self, serializer: &mut instant_xml::Serializer) -> Result<(), instant_xml::Error> - where - W: std::fmt::Write, - { + fn serialize(&self, serializer: &mut instant_xml::Serializer) -> Result<(), instant_xml::Error> { let _ = serializer.consume_field_context(); let mut field_context = instant_xml::FieldContext { name: #root_name, diff --git a/instant-xml/src/impls.rs b/instant-xml/src/impls.rs index 48cb40d..c6d09ff 100644 --- a/instant-xml/src/impls.rs +++ b/instant-xml/src/impls.rs @@ -81,10 +81,10 @@ where macro_rules! to_xml_for_number { ($typ:ty) => { impl ToXml for $typ { - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write, - { + fn serialize( + &self, + serializer: &mut Serializer, + ) -> Result<(), Error> { DisplayToXml(self).serialize(serializer) } } @@ -322,10 +322,7 @@ to_xml_for_number!(f32); to_xml_for_number!(f64); impl ToXml for bool { - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write, - { + fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> { let value = match self { true => "true", false => "false", @@ -336,50 +333,32 @@ impl ToXml for bool { } impl ToXml for String { - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write, - { + fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> { DisplayToXml(&escape(self)?).serialize(serializer) } } impl ToXml for char { - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write, - { + fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> { let mut tmp = [0u8; 4]; DisplayToXml(&escape(&*self.encode_utf8(&mut tmp))?).serialize(serializer) } } impl ToXml for &str { - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write, - { + fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> { DisplayToXml(&escape(self)?).serialize(serializer) } } impl ToXml for Cow<'_, str> { - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write, - { + fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> { DisplayToXml(&escape(self)?).serialize(serializer) } } -impl ToXml for Option -where - T: ToXml, -{ - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write, - { +impl ToXml for Option { + fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> { match self { Some(v) => v.serialize(serializer), None => Ok(()), diff --git a/instant-xml/src/lib.rs b/instant-xml/src/lib.rs index 26df04b..3aefe7e 100644 --- a/instant-xml/src/lib.rs +++ b/instant-xml/src/lib.rs @@ -34,15 +34,10 @@ pub trait ToXml { Ok(output) } - fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error> - where - W: fmt::Write; + fn serialize(&self, serializer: &mut Serializer) -> Result<(), Error>; } -pub struct Serializer<'xml, W> -where - W: fmt::Write, -{ +pub struct Serializer<'xml, W: fmt::Write> { // For parent namespaces the key is the namespace and the value is the prefix. We are adding to map // only if the namespaces do not exist, if it does exist then we are using an already defined parent prefix. #[doc(hidden)] @@ -56,7 +51,7 @@ where next_field_context: Option>, } -impl<'xml, W: std::fmt::Write> Serializer<'xml, W> { +impl<'xml, W: fmt::Write> Serializer<'xml, W> { pub fn new(output: &'xml mut W) -> Self { Self { parent_namespaces: HashMap::new(), @@ -74,20 +69,14 @@ impl<'xml, W: std::fmt::Write> Serializer<'xml, W> { Ok(()) } - pub fn add_attribute_key(&mut self, attr_key: &T) -> Result<(), Error> - where - T: fmt::Display, - { + pub fn add_attribute_key(&mut self, attr_key: &impl fmt::Display) -> Result<(), Error> { self.current_attributes.push(' '); write!(self.current_attributes, "{}", attr_key)?; self.current_attributes.push('='); Ok(()) } - pub fn add_attribute_value(&mut self, attr_value: &T) -> Result<(), Error> - where - T: fmt::Display, - { + pub fn add_attribute_value(&mut self, attr_value: &impl fmt::Display) -> Result<(), Error> { self.current_attributes.push('"'); write!(self.current_attributes, "{}", attr_value)?; self.current_attributes.push('"');