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

Converts this name to an internal slice representation.

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");

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()));

The same as (qname.local_name(), qname.prefix()), but does only one lookup for a ':' symbol.

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

Converts this type into a shared reference of the (usually inferred) input type.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Deserialize this value from the given Serde deserializer. Read more

Creates LocalName from a QName

Examples

let local: LocalName = QName(b"unprefixed").into();
assert_eq!(local.as_ref(), b"unprefixed");

let local: LocalName = QName(b"some:prefix").into();
assert_eq!(local.as_ref(), b"prefix");

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.