From 6f9c636c40b5e974e0324d55974e8c13380c86b0 Mon Sep 17 00:00:00 2001 From: Mingun Date: Sun, 10 Aug 2025 14:57:56 +0500 Subject: [PATCH] Remove deprecated items (TODO: edit changelog after release 0.39) --- Changelog.md | 4 + src/name.rs | 4 - src/reader/ns_reader.rs | 258 +--------------------------------------- 3 files changed, 5 insertions(+), 261 deletions(-) diff --git a/Changelog.md b/Changelog.md index 1dd92753..faaabd0f 100644 --- a/Changelog.md +++ b/Changelog.md @@ -25,8 +25,12 @@ of `NsReader`. Use `.resolver().bindings()` and `.resolver().resolve()` methods instead. - [#913]: `Attributes::has_nil` now accepts `NamespaceResolver` instead of `Reader`. +- [#914]: Remove deprecated `.prefixes()`, `.resolve()`, `.resolve_attribute()`, and `.resolve_element()` + of `NsReader`. Use `.resolver().<...>` methods instead. + [#908]: https://github.com/tafia/quick-xml/pull/908 [#913]: https://github.com/tafia/quick-xml/pull/913 +[#914]: https://github.com/tafia/quick-xml/pull/914 ## 0.38.4 -- 2025-11-11 diff --git a/src/name.rs b/src/name.rs index 09f675d2..498c422d 100644 --- a/src/name.rs +++ b/src/name.rs @@ -1081,10 +1081,6 @@ impl<'a> Iterator for NamespaceBindingsIter<'a> { impl<'a> FusedIterator for NamespaceBindingsIter<'a> {} -/// The previous name for [`NamespaceBindingsIter`]. -#[deprecated = "Use NamespaceBindingsIter instead. This alias will be removed in 0.40.0"] -pub type PrefixIter<'a> = NamespaceBindingsIter<'a>; - /// Iterator on the declared namespace bindings on specified level. Returns pairs of the _(prefix, namespace)_. /// /// See [`NamespaceResolver::bindings_of`] for documentation. diff --git a/src/reader/ns_reader.rs b/src/reader/ns_reader.rs index a3b33746..1ddfd1b9 100644 --- a/src/reader/ns_reader.rs +++ b/src/reader/ns_reader.rs @@ -12,7 +12,7 @@ use std::path::Path; use crate::errors::Result; use crate::events::Event; -use crate::name::{LocalName, NamespaceBindingsIter, NamespaceResolver, QName, ResolveResult}; +use crate::name::{NamespaceResolver, QName, ResolveResult}; use crate::reader::{Config, Reader, Span, XmlSource}; /// A low level encoding-agnostic XML event reader that performs namespace resolution. @@ -49,91 +49,6 @@ impl NsReader { pub fn config_mut(&mut self) -> &mut Config { self.reader.config_mut() } - - /// Returns all the prefixes currently declared except the default `xml` and `xmlns` namespaces. - /// - /// # Examples - /// - /// This example shows what results the returned iterator would return after - /// reading each event of a simple XML. - /// - /// ``` - /// # use pretty_assertions::assert_eq; - /// use quick_xml::name::{Namespace, PrefixDeclaration}; - /// use quick_xml::NsReader; - /// - /// let src = " - /// - /// - /// - /// - /// - /// - /// "; - /// let mut reader = NsReader::from_str(src); - /// reader.config_mut().trim_text(true); - /// // No prefixes at the beginning - /// assert_eq!(reader.prefixes().collect::>(), vec![]); - /// - /// reader.read_resolved_event()?; // - /// // No prefixes declared on root - /// assert_eq!(reader.prefixes().collect::>(), vec![]); - /// - /// reader.read_resolved_event()?; // - /// // Two prefixes declared on "a" - /// assert_eq!(reader.prefixes().collect::>(), vec![ - /// (PrefixDeclaration::Default, Namespace(b"a1")), - /// (PrefixDeclaration::Named(b"a"), Namespace(b"a2")) - /// ]); - /// - /// reader.read_resolved_event()?; // - /// // The default prefix got overridden and new "b" prefix - /// assert_eq!(reader.prefixes().collect::>(), vec![ - /// (PrefixDeclaration::Named(b"a"), Namespace(b"a2")), - /// (PrefixDeclaration::Default, Namespace(b"b1")), - /// (PrefixDeclaration::Named(b"b"), Namespace(b"b2")) - /// ]); - /// - /// reader.read_resolved_event()?; // - /// // Still the same - /// assert_eq!(reader.prefixes().collect::>(), vec![ - /// (PrefixDeclaration::Named(b"a"), Namespace(b"a2")), - /// (PrefixDeclaration::Default, Namespace(b"b1")), - /// (PrefixDeclaration::Named(b"b"), Namespace(b"b2")) - /// ]); - /// - /// reader.read_resolved_event()?; // - /// // Still the same - /// assert_eq!(reader.prefixes().collect::>(), vec![ - /// (PrefixDeclaration::Named(b"a"), Namespace(b"a2")), - /// (PrefixDeclaration::Default, Namespace(b"b1")), - /// (PrefixDeclaration::Named(b"b"), Namespace(b"b2")) - /// ]); - /// - /// reader.read_resolved_event()?; // - /// // got closed so back to the prefixes declared on - /// assert_eq!(reader.prefixes().collect::>(), vec![ - /// (PrefixDeclaration::Default, Namespace(b"a1")), - /// (PrefixDeclaration::Named(b"a"), Namespace(b"a2")) - /// ]); - /// - /// reader.read_resolved_event()?; // - /// // Still the same - /// assert_eq!(reader.prefixes().collect::>(), vec![ - /// (PrefixDeclaration::Default, Namespace(b"a1")), - /// (PrefixDeclaration::Named(b"a"), Namespace(b"a2")) - /// ]); - /// - /// reader.read_resolved_event()?; // - /// // got closed - /// assert_eq!(reader.prefixes().collect::>(), vec![]); - /// # quick_xml::Result::Ok(()) - /// ``` - #[inline] - #[deprecated = "Use `.resolver().bindings()` instead. This method will be removed in 0.40.0"] - pub const fn prefixes(&self) -> NamespaceBindingsIter<'_> { - self.ns_resolver.bindings() - } } /// Private methods @@ -207,177 +122,6 @@ impl NsReader { pub const fn resolver(&self) -> &NamespaceResolver { &self.ns_resolver } - - /// Resolves a potentially qualified **element name** or **attribute name** - /// into _(namespace name, local name)_. - /// - /// _Qualified_ names have the form `local-name` or `prefix:local-name` where the `prefix` - /// is defined on any containing XML element via `xmlns:prefix="the:namespace:uri"`. - /// The namespace prefix can be defined on the same element as the name in question. - /// - /// The method returns following results depending on the `name` shape, `attribute` flag - /// and the presence of the default namespace on element or any of its parents: - /// - /// |attribute|`xmlns="..."`|QName |ResolveResult |LocalName - /// |---------|-------------|-------------------|-----------------------|------------ - /// |`true` |_(any)_ |`local-name` |[`Unbound`] |`local-name` - /// |`true` |_(any)_ |`prefix:local-name`|[`Bound`] / [`Unknown`]|`local-name` - /// |`false` |Not defined |`local-name` |[`Unbound`] |`local-name` - /// |`false` |Defined |`local-name` |[`Bound`] (to `xmlns`) |`local-name` - /// |`false` |_(any)_ |`prefix:local-name`|[`Bound`] / [`Unknown`]|`local-name` - /// - /// If you want to clearly indicate that name that you resolve is an element - /// or an attribute name, you could use [`resolve_attribute()`] or [`resolve_element()`] - /// methods. - /// - /// # Lifetimes - /// - /// - `'n`: lifetime of a name. Returned local name will be bound to the same - /// lifetime as the name in question. - /// - returned namespace name will be bound to the reader itself - /// - /// [`Bound`]: ResolveResult::Bound - /// [`Unbound`]: ResolveResult::Unbound - /// [`Unknown`]: ResolveResult::Unknown - /// [`resolve_attribute()`]: Self::resolve_attribute() - /// [`resolve_element()`]: Self::resolve_element() - #[inline] - #[deprecated = "Use `.resolver().resolve()` instead. Note, that boolean argument should be inverted! This method will be removed in 0.40.0"] - pub fn resolve<'n>( - &self, - name: QName<'n>, - attribute: bool, - ) -> (ResolveResult<'_>, LocalName<'n>) { - self.ns_resolver.resolve(name, !attribute) - } - - /// Resolves a potentially qualified **element name** into _(namespace name, local name)_. - /// - /// _Qualified_ element names have the form `prefix:local-name` where the - /// `prefix` is defined on any containing XML element via `xmlns:prefix="the:namespace:uri"`. - /// The namespace prefix can be defined on the same element as the element - /// in question. - /// - /// _Unqualified_ elements inherits the current _default namespace_. - /// - /// The method returns following results depending on the `name` shape and - /// the presence of the default namespace: - /// - /// |`xmlns="..."`|QName |ResolveResult |LocalName - /// |-------------|-------------------|-----------------------|------------ - /// |Not defined |`local-name` |[`Unbound`] |`local-name` - /// |Defined |`local-name` |[`Bound`] (default) |`local-name` - /// |_any_ |`prefix:local-name`|[`Bound`] / [`Unknown`]|`local-name` - /// - /// # Lifetimes - /// - /// - `'n`: lifetime of an element name. Returned local name will be bound - /// to the same lifetime as the name in question. - /// - returned namespace name will be bound to the reader itself - /// - /// # Examples - /// - /// This example shows how you can resolve qualified name into a namespace. - /// Note, that in the code like this you do not need to do that manually, - /// because the namespace resolution result returned by the [`read_resolved_event()`]. - /// - /// ``` - /// # use pretty_assertions::assert_eq; - /// use quick_xml::events::Event; - /// use quick_xml::name::{Namespace, QName, ResolveResult::*}; - /// use quick_xml::reader::NsReader; - /// - /// let mut reader = NsReader::from_str(""); - /// - /// match reader.read_event().unwrap() { - /// Event::Empty(e) => assert_eq!( - /// reader.resolve_element(e.name()), - /// (Bound(Namespace(b"root namespace")), QName(b"tag").into()) - /// ), - /// _ => unreachable!(), - /// } - /// ``` - /// - /// [`Bound`]: ResolveResult::Bound - /// [`Unbound`]: ResolveResult::Unbound - /// [`Unknown`]: ResolveResult::Unknown - /// [`read_resolved_event()`]: Self::read_resolved_event - #[inline] - #[deprecated = "Use `.resolver().resolve_element()` instead. This method will be removed in 0.40.0"] - pub fn resolve_element<'n>(&self, name: QName<'n>) -> (ResolveResult<'_>, LocalName<'n>) { - self.ns_resolver.resolve_element(name) - } - - /// Resolves a potentially qualified **attribute name** into _(namespace name, local name)_. - /// - /// _Qualified_ attribute names have the form `prefix:local-name` where the - /// `prefix` is defined on any containing XML element via `xmlns:prefix="the:namespace:uri"`. - /// The namespace prefix can be defined on the same element as the attribute - /// in question. - /// - /// _Unqualified_ attribute names do *not* inherit the current _default namespace_. - /// - /// The method returns following results depending on the `name` shape and - /// the presence of the default namespace: - /// - /// |`xmlns="..."`|QName |ResolveResult |LocalName - /// |-------------|-------------------|-----------------------|------------ - /// |Not defined |`local-name` |[`Unbound`] |`local-name` - /// |Defined |`local-name` |[`Unbound`] |`local-name` - /// |_any_ |`prefix:local-name`|[`Bound`] / [`Unknown`]|`local-name` - /// - /// # Lifetimes - /// - /// - `'n`: lifetime of an attribute name. Returned local name will be bound - /// to the same lifetime as the name in question. - /// - returned namespace name will be bound to the reader itself - /// - /// # Examples - /// - /// ``` - /// # use pretty_assertions::assert_eq; - /// use quick_xml::events::Event; - /// use quick_xml::name::{Namespace, QName, ResolveResult::*}; - /// use quick_xml::reader::NsReader; - /// - /// let mut reader = NsReader::from_str(" - /// - /// "); - /// reader.config_mut().trim_text(true); - /// - /// match reader.read_event().unwrap() { - /// Event::Empty(e) => { - /// let mut iter = e.attributes(); - /// - /// // Unlike elements, attributes without explicit namespace - /// // not bound to any namespace - /// let one = iter.next().unwrap().unwrap(); - /// assert_eq!( - /// reader.resolve_attribute(one.key), - /// (Unbound, QName(b"one").into()) - /// ); - /// - /// let two = iter.next().unwrap().unwrap(); - /// assert_eq!( - /// reader.resolve_attribute(two.key), - /// (Bound(Namespace(b"other namespace")), QName(b"two").into()) - /// ); - /// } - /// _ => unreachable!(), - /// } - /// ``` - /// - /// [`Bound`]: ResolveResult::Bound - /// [`Unbound`]: ResolveResult::Unbound - /// [`Unknown`]: ResolveResult::Unknown - #[inline] - #[deprecated = "Use `.resolver().resolve_attribute()` instead. This method will be removed in 0.40.0"] - pub fn resolve_attribute<'n>(&self, name: QName<'n>) -> (ResolveResult<'_>, LocalName<'n>) { - self.ns_resolver.resolve_attribute(name) - } } impl NsReader {