diff --git a/Cargo.toml b/Cargo.toml index b28502b..5034696 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,7 +8,7 @@ license = "MIT OR Apache-2.0" repository = "https://github.com/adamreichold/serde-roxmltree" documentation = "https://docs.rs/serde-roxmltree" readme = "README.md" -version = "0.7.1" +version = "0.7.2" edition = "2021" [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 88f300d..4523527 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -247,20 +247,7 @@ pub trait Options: Sized { } #[doc(hidden)] - #[allow(private_interfaces)] - fn name<'de, 'input, 'temp>( - source: &Source<'de, 'input>, - _buffer: &'temp mut String, - ) -> &'temp str - where - 'input: 'temp, - { - match source { - Source::Node(node) => node.tag_name().name(), - Source::Attribute(attr) => attr.name(), - Source::Text(_) => "$text", - } - } + const NAMESPACES: bool = false; } #[doc(hidden)] @@ -279,14 +266,38 @@ impl Options for Defaults {} pub struct Namespaces(PhantomData); impl Options for Namespaces { - #[allow(private_interfaces)] - fn name<'de, 'input, 'temp>( - source: &Source<'de, 'input>, - buffer: &'temp mut String, - ) -> &'temp str - where - 'input: 'temp, - { + const NAMESPACES: bool = true; +} + +struct Deserializer<'de, 'input, 'temp, O> { + source: Source<'de, 'input>, + temp: &'temp mut Temp, + options: PhantomData, +} + +#[derive(Clone, Copy)] +enum Source<'de, 'input> { + Node(Node<'de, 'input>), + Attribute(Attribute<'de, 'input>), + Text(&'de str), +} + +#[derive(Default)] +struct Temp { + visited: BitSet, + buffer: String, +} + +impl<'de, 'input, 'temp, O> Deserializer<'de, 'input, 'temp, O> { + fn name(&self) -> &'de str { + match &self.source { + Source::Node(node) => node.tag_name().name(), + Source::Attribute(attr) => attr.name(), + Source::Text(_) => "$text", + } + } + + fn qualified_name(&mut self) -> &str { fn inner<'input, 'temp>( namespace: Option<&str>, name: &'input str, @@ -312,37 +323,16 @@ impl Options for Namespaces { } } - match source { + match &self.source { Source::Node(node) => { let tag_name = node.tag_name(); - inner(tag_name.namespace(), tag_name.name(), buffer) + inner(tag_name.namespace(), tag_name.name(), &mut self.temp.buffer) } - Source::Attribute(attr) => inner(attr.namespace(), attr.name(), buffer), + Source::Attribute(attr) => inner(attr.namespace(), attr.name(), &mut self.temp.buffer), Source::Text(_) => "$text", } } -} - -struct Deserializer<'de, 'input, 'temp, O> { - source: Source<'de, 'input>, - temp: &'temp mut Temp, - options: PhantomData, -} -#[derive(Clone, Copy)] -enum Source<'de, 'input> { - Node(Node<'de, 'input>), - Attribute(Attribute<'de, 'input>), - Text(&'de str), -} - -#[derive(Default)] -struct Temp { - visited: BitSet, - buffer: String, -} - -impl<'de, 'input, 'temp, O> Deserializer<'de, 'input, 'temp, O> { fn node(&self) -> Result<&Node<'de, 'input>, Error> { match &self.source { Source::Node(node) => Ok(node), @@ -614,11 +604,15 @@ where }) } - fn deserialize_identifier(self, visitor: V) -> Result + fn deserialize_identifier(mut self, visitor: V) -> Result where V: de::Visitor<'de>, { - visitor.visit_str(O::name(&self.source, &mut self.temp.buffer)) + if O::NAMESPACES { + visitor.visit_str(self.qualified_name()) + } else { + visitor.visit_borrowed_str(self.name()) + } } fn deserialize_any(self, _visitor: V) -> Result