diff --git a/instant-xml-macros/src/de.rs b/instant-xml-macros/src/de.rs index 20fee2f..a97cc73 100644 --- a/instant-xml-macros/src/de.rs +++ b/instant-xml-macros/src/de.rs @@ -58,7 +58,7 @@ fn deserialize_enum( } } - const KIND: ::instant_xml::Kind = ::instant_xml::Kind::Scalar; + const KIND: ::instant_xml::Kind<'static> = ::instant_xml::Kind::Scalar; } ) } @@ -193,7 +193,7 @@ fn deserialize_struct( Ok(Self { #return_val }) } - const KIND: ::instant_xml::Kind = ::instant_xml::Kind::Element(::instant_xml::Id { + const KIND: ::instant_xml::Kind<'static> = ::instant_xml::Kind::Element(::instant_xml::Id { ns: #default_namespace, name: #name, }); diff --git a/instant-xml-macros/src/ser.rs b/instant-xml-macros/src/ser.rs index 5a3d0bd..3bbc88f 100644 --- a/instant-xml-macros/src/ser.rs +++ b/instant-xml-macros/src/ser.rs @@ -55,7 +55,7 @@ fn serialize_enum( serializer.write_str(match self { #variants }) } - const KIND: ::instant_xml::Kind = ::instant_xml::Kind::Scalar; + const KIND: ::instant_xml::Kind<'static> = ::instant_xml::Kind::Scalar; } ) } @@ -129,7 +129,7 @@ fn serialize_struct( Ok(()) } - const KIND: ::instant_xml::Kind = ::instant_xml::Kind::Element(::instant_xml::Id { + const KIND: ::instant_xml::Kind<'static> = ::instant_xml::Kind::Element(::instant_xml::Id { ns: #default_namespace, name: #tag, }); diff --git a/instant-xml/src/impls.rs b/instant-xml/src/impls.rs index edd09bd..2773b21 100644 --- a/instant-xml/src/impls.rs +++ b/instant-xml/src/impls.rs @@ -19,7 +19,7 @@ impl<'xml, T: FromStr> FromXml<'xml> for FromXmlStr { } } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } impl<'xml> FromXml<'xml> for bool { @@ -29,7 +29,7 @@ impl<'xml> FromXml<'xml> for bool { .ok_or(Error::MissingValue) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } // Serializer @@ -46,7 +46,7 @@ where serializer.write_str(self.0) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } macro_rules! to_xml_for_number { @@ -59,7 +59,7 @@ macro_rules! to_xml_for_number { DisplayToXml(self).serialize(serializer) } - const KIND: Kind = DisplayToXml::::KIND; + const KIND: Kind<'static> = DisplayToXml::::KIND; } }; } @@ -75,7 +75,7 @@ macro_rules! from_xml_for_number { .ok_or(Error::MissingValue) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } }; } @@ -100,7 +100,7 @@ impl<'xml> FromXml<'xml> for char { .ok_or(Error::MissingValue) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } impl<'xml> FromXml<'xml> for String { @@ -108,7 +108,7 @@ impl<'xml> FromXml<'xml> for String { Ok( as FromXml<'xml>>::deserialize(deserializer)?.into_owned()) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } impl<'xml> FromXml<'xml> for &'xml str { @@ -121,7 +121,7 @@ impl<'xml> FromXml<'xml> for &'xml str { ) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } impl<'xml> FromXml<'xml> for Cow<'xml, str> { @@ -130,7 +130,7 @@ impl<'xml> FromXml<'xml> for Cow<'xml, str> { Ok(decode(value)) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } impl<'xml, T> FromXml<'xml> for Option @@ -148,7 +148,7 @@ where Ok(None) } - const KIND: Kind = ::KIND; + const KIND: Kind<'static> = ::KIND; } to_xml_for_number!(i8); @@ -177,7 +177,7 @@ impl ToXml for bool { DisplayToXml(&value).serialize(serializer) } - const KIND: Kind = DisplayToXml::::KIND; + const KIND: Kind<'static> = DisplayToXml::::KIND; } impl ToXml for String { @@ -188,7 +188,7 @@ impl ToXml for String { DisplayToXml(&encode(self)?).serialize(serializer) } - const KIND: Kind = DisplayToXml::::KIND; + const KIND: Kind<'static> = DisplayToXml::::KIND; } impl ToXml for char { @@ -200,7 +200,7 @@ impl ToXml for char { DisplayToXml(&encode(&*self.encode_utf8(&mut tmp))?).serialize(serializer) } - const KIND: Kind = DisplayToXml::::KIND; + const KIND: Kind<'static> = DisplayToXml::::KIND; } impl ToXml for &str { @@ -211,7 +211,7 @@ impl ToXml for &str { DisplayToXml(&encode(self)?).serialize(serializer) } - const KIND: Kind = DisplayToXml::::KIND; + const KIND: Kind<'static> = DisplayToXml::::KIND; } impl ToXml for Cow<'_, str> { @@ -222,7 +222,7 @@ impl ToXml for Cow<'_, str> { DisplayToXml(&encode(self)?).serialize(serializer) } - const KIND: Kind = DisplayToXml::::KIND; + const KIND: Kind<'static> = DisplayToXml::::KIND; } impl ToXml for Option { @@ -236,7 +236,7 @@ impl ToXml for Option { } } - const KIND: Kind = T::KIND; + const KIND: Kind<'static> = T::KIND; } fn encode(input: &str) -> Result, Error> { @@ -355,7 +355,7 @@ where Ok(result) } - const KIND: Kind = Kind::Vec; + const KIND: Kind<'static> = Kind::Vec; } impl ToXml for Vec @@ -394,7 +394,7 @@ where Ok(()) } - const KIND: Kind = Kind::Vec; + const KIND: Kind<'static> = Kind::Vec; } #[cfg(feature = "chrono")] @@ -406,7 +406,7 @@ impl ToXml for DateTime { serializer.write_str(&self.to_rfc3339()) } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } #[cfg(feature = "chrono")] @@ -419,5 +419,5 @@ impl<'xml> FromXml<'xml> for DateTime { } } - const KIND: Kind = Kind::Scalar; + const KIND: Kind<'static> = Kind::Scalar; } diff --git a/instant-xml/src/lib.rs b/instant-xml/src/lib.rs index ba57ea4..8ef2c4f 100644 --- a/instant-xml/src/lib.rs +++ b/instant-xml/src/lib.rs @@ -19,7 +19,7 @@ pub trait ToXml { serializer: &mut Serializer, ) -> Result<(), Error>; - const KIND: Kind; + const KIND: Kind<'static>; } impl<'a, T: ToXml + ?Sized> ToXml for &'a T { @@ -30,7 +30,7 @@ impl<'a, T: ToXml + ?Sized> ToXml for &'a T { (*self).serialize(serializer) } - const KIND: Kind = T::KIND; + const KIND: Kind<'static> = T::KIND; } pub trait FromXml<'xml>: Sized { @@ -42,7 +42,7 @@ pub trait FromXml<'xml>: Sized { Err(Error::MissingValue) } - const KIND: Kind; + const KIND: Kind<'static>; } pub fn from_str<'xml, T: FromXml<'xml>>(input: &'xml str) -> Result { @@ -110,14 +110,14 @@ pub enum Error { DuplicateValue, } -pub enum Kind { +pub enum Kind<'a> { Scalar, - Element(Id<'static>), + Element(Id<'a>), Vec, } -impl Kind { - pub const fn name(&self, field: Id<'static>) -> Id<'static> { +impl<'a> Kind<'a> { + pub const fn name(&self, field: Id<'a>) -> Id<'a> { match self { Kind::Scalar => field, Kind::Element(name) => *name,