Allow Kind to be variant over lifetime
This commit is contained in:
parent
433b0197bb
commit
1190c5c345
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
|
|
|
@ -19,7 +19,7 @@ impl<'xml, T: FromStr> FromXml<'xml> for FromXmlStr<T> {
|
|||
}
|
||||
}
|
||||
|
||||
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::<Self>::KIND;
|
||||
const KIND: Kind<'static> = DisplayToXml::<Self>::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(<Cow<'xml, str> 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<T>
|
||||
|
@ -148,7 +148,7 @@ where
|
|||
Ok(None)
|
||||
}
|
||||
|
||||
const KIND: Kind = <T>::KIND;
|
||||
const KIND: Kind<'static> = <T>::KIND;
|
||||
}
|
||||
|
||||
to_xml_for_number!(i8);
|
||||
|
@ -177,7 +177,7 @@ impl ToXml for bool {
|
|||
DisplayToXml(&value).serialize(serializer)
|
||||
}
|
||||
|
||||
const KIND: Kind = DisplayToXml::<Self>::KIND;
|
||||
const KIND: Kind<'static> = DisplayToXml::<Self>::KIND;
|
||||
}
|
||||
|
||||
impl ToXml for String {
|
||||
|
@ -188,7 +188,7 @@ impl ToXml for String {
|
|||
DisplayToXml(&encode(self)?).serialize(serializer)
|
||||
}
|
||||
|
||||
const KIND: Kind = DisplayToXml::<Self>::KIND;
|
||||
const KIND: Kind<'static> = DisplayToXml::<Self>::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::<Self>::KIND;
|
||||
const KIND: Kind<'static> = DisplayToXml::<Self>::KIND;
|
||||
}
|
||||
|
||||
impl ToXml for &str {
|
||||
|
@ -211,7 +211,7 @@ impl ToXml for &str {
|
|||
DisplayToXml(&encode(self)?).serialize(serializer)
|
||||
}
|
||||
|
||||
const KIND: Kind = DisplayToXml::<Self>::KIND;
|
||||
const KIND: Kind<'static> = DisplayToXml::<Self>::KIND;
|
||||
}
|
||||
|
||||
impl ToXml for Cow<'_, str> {
|
||||
|
@ -222,7 +222,7 @@ impl ToXml for Cow<'_, str> {
|
|||
DisplayToXml(&encode(self)?).serialize(serializer)
|
||||
}
|
||||
|
||||
const KIND: Kind = DisplayToXml::<Self>::KIND;
|
||||
const KIND: Kind<'static> = DisplayToXml::<Self>::KIND;
|
||||
}
|
||||
|
||||
impl<T: ToXml> ToXml for Option<T> {
|
||||
|
@ -236,7 +236,7 @@ impl<T: ToXml> ToXml for Option<T> {
|
|||
}
|
||||
}
|
||||
|
||||
const KIND: Kind = T::KIND;
|
||||
const KIND: Kind<'static> = T::KIND;
|
||||
}
|
||||
|
||||
fn encode(input: &str) -> Result<Cow<'_, str>, Error> {
|
||||
|
@ -355,7 +355,7 @@ where
|
|||
Ok(result)
|
||||
}
|
||||
|
||||
const KIND: Kind = Kind::Vec;
|
||||
const KIND: Kind<'static> = Kind::Vec;
|
||||
}
|
||||
|
||||
impl<T> ToXml for Vec<T>
|
||||
|
@ -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<Utc> {
|
|||
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<Utc> {
|
|||
}
|
||||
}
|
||||
|
||||
const KIND: Kind = Kind::Scalar;
|
||||
const KIND: Kind<'static> = Kind::Scalar;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ pub trait ToXml {
|
|||
serializer: &mut Serializer<W>,
|
||||
) -> 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<T, Error> {
|
||||
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue