pub struct QName<'a>(pub &'a [u8]);
Expand description
A qualified name of an element or an attribute, including an optional namespace prefix and a local name.
Tuple Fields§
§0: &'a [u8]
Implementations§
source§impl<'a> QName<'a>
impl<'a> QName<'a>
sourcepub fn into_inner(self) -> &'a [u8] ⓘ
pub fn into_inner(self) -> &'a [u8] ⓘ
Converts this name to an internal slice representation.
sourcepub fn local_name(&self) -> LocalName<'a>
pub fn local_name(&self) -> LocalName<'a>
Returns local part of this qualified name.
All content up to and including the first :
character is removed from
the tag name.
Examples
let simple = QName(b"simple-name");
assert_eq!(simple.local_name().as_ref(), b"simple-name");
let qname = QName(b"namespace:simple-name");
assert_eq!(qname.local_name().as_ref(), b"simple-name");
sourcepub fn prefix(&self) -> Option<Prefix<'a>>
pub fn prefix(&self) -> Option<Prefix<'a>>
Returns namespace part of this qualified name or None
if namespace part
is not defined (symbol ':'
not found).
Examples
let simple = QName(b"simple-name");
assert_eq!(simple.prefix(), None);
let qname = QName(b"prefix:simple-name");
assert_eq!(qname.prefix().as_ref().map(|n| n.as_ref()), Some(b"prefix".as_ref()));
sourcepub fn decompose(&self) -> (LocalName<'a>, Option<Prefix<'a>>)
pub fn decompose(&self) -> (LocalName<'a>, Option<Prefix<'a>>)
The same as (qname.local_name(), qname.prefix())
, but does only one
lookup for a ':'
symbol.
sourcepub fn as_namespace_binding(&self) -> Option<PrefixDeclaration<'a>>
pub fn as_namespace_binding(&self) -> Option<PrefixDeclaration<'a>>
If that QName
represents "xmlns"
series of names, returns Some
,
otherwise None
is returned.
Examples
let qname = QName(b"xmlns");
assert_eq!(qname.as_namespace_binding(), Some(PrefixDeclaration::Default));
let qname = QName(b"xmlns:prefix");
assert_eq!(qname.as_namespace_binding(), Some(PrefixDeclaration::Named(b"prefix")));
// Be aware that this method does not check the validity of the prefix - it can be empty!
let qname = QName(b"xmlns:");
assert_eq!(qname.as_namespace_binding(), Some(PrefixDeclaration::Named(b"")));
let qname = QName(b"other-name");
assert_eq!(qname.as_namespace_binding(), None);
// https://www.w3.org/TR/xml-names11/#xmlReserved
let qname = QName(b"xmlns-reserved-name");
assert_eq!(qname.as_namespace_binding(), None);
Trait Implementations§
source§impl<'de: 'a, 'a> Deserialize<'de> for QName<'a>
impl<'de: 'a, 'a> Deserialize<'de> for QName<'a>
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl<'a> Ord for QName<'a>
impl<'a> Ord for QName<'a>
source§impl<'a> PartialEq for QName<'a>
impl<'a> PartialEq for QName<'a>
source§impl<'a> PartialOrd for QName<'a>
impl<'a> PartialOrd for QName<'a>
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl<'a> Copy for QName<'a>
impl<'a> Eq for QName<'a>
impl<'a> StructuralEq for QName<'a>
impl<'a> StructuralPartialEq for QName<'a>
Auto Trait Implementations§
impl<'a> RefUnwindSafe for QName<'a>
impl<'a> Send for QName<'a>
impl<'a> Sync for QName<'a>
impl<'a> Unpin for QName<'a>
impl<'a> UnwindSafe for QName<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more