From 20b224855c1780bca7b78df24af9e0fe2391030a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maxime=20=E2=80=9Cpep=E2=80=9D=20Buquet?= Date: Thu, 26 Mar 2020 21:42:40 +0100 Subject: [PATCH] minidom: Remove NSChoice::None MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Although it is still possible to create such elements, this is not a a case that should happen in XMPP. Changing to API to prevent the creation of these elements is next on the list. Signed-off-by: Maxime “pep” Buquet --- minidom-rs/src/element.rs | 21 --------------------- minidom-rs/src/namespace_set.rs | 5 +---- 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/minidom-rs/src/element.rs b/minidom-rs/src/element.rs index 8abe01f..a663c73 100644 --- a/minidom-rs/src/element.rs +++ b/minidom-rs/src/element.rs @@ -280,7 +280,6 @@ impl Element { /// assert_eq!(elem.is("wrong", "namespace"), false); /// assert_eq!(elem.is("wrong", "wrong"), false); /// - /// assert_eq!(elem.is("name", NSChoice::None), false); /// assert_eq!(elem.is("name", NSChoice::OneOf("namespace")), true); /// assert_eq!(elem.is("name", NSChoice::OneOf("foo")), false); /// assert_eq!(elem.is("name", NSChoice::AnyOf(&["foo", "namespace"])), true); @@ -288,7 +287,6 @@ impl Element { /// /// let elem2 = Element::builder("name").build(); /// - /// assert_eq!(elem2.is("name", NSChoice::None), true); /// assert_eq!(elem2.is("name", NSChoice::Any), true); /// ``` pub fn is<'a, N: AsRef, NS: Into>>(&self, name: N, namespace: NS) -> bool { @@ -307,7 +305,6 @@ impl Element { /// assert_eq!(elem.has_ns("namespace"), true); /// assert_eq!(elem.has_ns("wrong"), false); /// - /// assert_eq!(elem.has_ns(NSChoice::None), false); /// assert_eq!(elem.has_ns(NSChoice::OneOf("namespace")), true); /// assert_eq!(elem.has_ns(NSChoice::OneOf("foo")), false); /// assert_eq!(elem.has_ns(NSChoice::AnyOf(&["foo", "namespace"])), true); @@ -315,7 +312,6 @@ impl Element { /// /// let elem2 = Element::builder("name").build(); /// - /// assert_eq!(elem2.has_ns(NSChoice::None), true); /// assert_eq!(elem2.has_ns(NSChoice::Any), true); /// ``` pub fn has_ns<'a, NS: Into>>(&self, namespace: NS) -> bool { @@ -667,12 +663,6 @@ impl Element { /// assert_eq!(elem.get_child("c", "ns"), None); /// assert_eq!(elem.get_child("b", "other_ns"), None); /// assert_eq!(elem.get_child("a", "inexistent_ns"), None); - /// - /// let elem: Element = r#""#.parse().unwrap(); - /// assert_eq!(elem.get_child("a", NSChoice::None), None); - /// assert!(elem.get_child("a", NSChoice::Any).unwrap().is("a", "other_ns")); - /// assert!(elem.get_child("b", NSChoice::None).unwrap().is("b", NSChoice::None)); - /// assert!(elem.get_child("b", NSChoice::Any).unwrap().is("b", NSChoice::None)); /// ``` pub fn get_child<'a, N: AsRef, NS: Into>>( &self, @@ -723,12 +713,6 @@ impl Element { /// assert_eq!(elem.has_child("b", "ns"), true); /// assert_eq!(elem.has_child("b", "other_ns"), false); /// assert_eq!(elem.has_child("b", "inexistent_ns"), false); - /// - /// let elem: Element = r#""#.parse().unwrap(); - /// assert_eq!(elem.has_child("a", NSChoice::None), false); - /// assert_eq!(elem.has_child("a", NSChoice::OneOf("other_ns")), true); - /// assert_eq!(elem.has_child("a", NSChoice::Any), true); - /// assert_eq!(elem.has_child("b", NSChoice::None), true); /// ``` pub fn has_child<'a, N: AsRef, NS: Into>>( &self, @@ -751,11 +735,6 @@ impl Element { /// assert!(elem.remove_child("a", "ns").unwrap().is("a", "ns")); /// assert!(elem.remove_child("a", "ns").is_none()); /// assert!(elem.remove_child("inexistent", "inexistent").is_none()); - /// - /// let mut elem: Element = r#""#.parse().unwrap(); - /// assert!(elem.remove_child("a", NSChoice::None).is_none()); - /// assert!(elem.remove_child("a", NSChoice::Any).unwrap().is("a", "other_ns")); - /// assert!(elem.remove_child("b", NSChoice::None).unwrap().is("b", NSChoice::None)); /// ``` pub fn remove_child<'a, N: AsRef, NS: Into>>( &mut self, diff --git a/minidom-rs/src/namespace_set.rs b/minidom-rs/src/namespace_set.rs index a42504d..986a92d 100644 --- a/minidom-rs/src/namespace_set.rs +++ b/minidom-rs/src/namespace_set.rs @@ -15,8 +15,6 @@ use std::rc::Rc; #[derive(Clone, Copy, PartialEq, Eq, Debug)] /// Use to compare namespaces pub enum NSChoice<'a> { - /// The element must have no namespace - None, /// The element's namespace must match the specified namespace OneOf(&'a str), /// The element's namespace must be in the specified vector @@ -34,9 +32,8 @@ impl<'a> From<&'a str> for NSChoice<'a> { impl<'a> NSChoice<'a> { fn compare(&self, ns: Option<&str>) -> bool { match (ns, &self) { - (None, NSChoice::None) | (None, NSChoice::Any) => true, + (None, NSChoice::Any) => true, (None, NSChoice::OneOf(_)) | (None, NSChoice::AnyOf(_)) => false, - (Some(_), NSChoice::None) => false, (Some(_), NSChoice::Any) => true, (Some(ns), NSChoice::OneOf(wanted_ns)) => &ns == wanted_ns, (Some(ns), NSChoice::AnyOf(wanted_nss)) => wanted_nss.iter().any(|w| &ns == w),