Struct ruma::html::QualName

source ·
pub struct QualName {
    pub prefix: Option<Atom<PrefixStaticSet>>,
    pub ns: Atom<NamespaceStaticSet>,
    pub local: Atom<LocalNameStaticSet>,
}
Expand description

A fully qualified name (with a namespace), used to depict names of tags and attributes.

Namespaces can be used to differentiate between similar XML fragments. For example:

// HTML
<table>
  <tr>
    <td>Apples</td>
    <td>Bananas</td>
  </tr>
</table>

// Furniture XML
<table>
  <name>African Coffee Table</name>
  <width>80</width>
  <length>120</length>
</table>

Without XML namespaces, we can’t use those two fragments in the same document at the same time. However if we declare a namespace we could instead say:


// Furniture XML
<furn:table xmlns:furn="https://furniture.rs">
  <furn:name>African Coffee Table</furn:name>
  <furn:width>80</furn:width>
  <furn:length>120</furn:length>
</furn:table>

and bind the prefix furn to a different namespace.

For this reason we parse names that contain a colon in the following way:

<furn:table>
   |    |
   |    +- local name
   |
 prefix (when resolved gives namespace_url `https://furniture.rs`)

NOTE: Prefix, LocalName and Prefix are all derivative of string_cache::atom::Atom and Atom implements Deref<str>.

Fields§

§prefix: Option<Atom<PrefixStaticSet>>

The prefix of qualified (e.g. furn in <furn:table> above). Optional (since some namespaces can be empty or inferred), and only useful for namespace resolution (since different prefix can still resolve to same namespace)


use markup5ever::{QualName, Namespace, LocalName, Prefix};

let qual = QualName::new(
    Some(Prefix::from("furn")),
    Namespace::from("https://furniture.rs"),
    LocalName::from("table"),
);

assert_eq!("furn", &qual.prefix.unwrap());
§ns: Atom<NamespaceStaticSet>

The namespace after resolution (e.g. https://furniture.rs in example above).



assert_eq!("https://furniture.rs", &qual.ns);

When matching namespaces used by HTML we can use ns! macro. Although keep in mind that ns! macro only works with namespaces that are present in HTML spec (like html, xmlns, svg, etc.).

#[macro_use] extern crate markup5ever;


let html_table = QualName::new(
   None,
   ns!(html),
   LocalName::from("table"),
);

assert!(
  match html_table.ns {
    ns!(html) => true,
    _ => false,
  }
);
§local: Atom<LocalNameStaticSet>

The local name (e.g. table in <furn:table> above).



assert_eq!("table", &qual.local);

When matching local name we can also use the local_name! macro:

#[macro_use] extern crate markup5ever;



// Initialize qual to furniture example

assert!(
  match qual.local {
    local_name!("table") => true,
    _ => false,
  }
);

Implementations§

source§

impl QualName

source

pub fn new( prefix: Option<Atom<PrefixStaticSet>>, ns: Atom<NamespaceStaticSet>, local: Atom<LocalNameStaticSet>, ) -> QualName

Basic constructor function.

First let’s try it for the following example where QualName is defined as:

<furn:table> <!-- namespace url is https://furniture.rs -->

Given this definition, we can define QualName using strings.

use markup5ever::{QualName, Namespace, LocalName, Prefix};

let qual_name = QualName::new(
    Some(Prefix::from("furn")),
    Namespace::from("https://furniture.rs"),
    LocalName::from("table"),
);

If we were instead to construct this element instead:


<table>
 ^^^^^---- no prefix and thus default html namespace

Or could define it using macros, like so:

#[macro_use] extern crate markup5ever;
use markup5ever::{QualName, Namespace, LocalName, Prefix};

let qual_name = QualName::new(
    None,
    ns!(html),
    local_name!("table")
);

Let’s analyse the above example. Since we have no prefix its value is None. Second we have html namespace. In html5ever html namespaces are supported out of the box, we can write ns!(html) instead of typing Namespace::from("http://www.w3.org/1999/xhtml"). Local name is also one of the HTML elements local names, so can use local_name!("table") macro.

source

pub fn expanded(&self) -> ExpandedName<'_>

Take a reference of self as an ExpandedName, dropping the unresolved prefix.

In XML and HTML prefixes are only used to extract the relevant namespace URI. Expanded name only contains resolved namespace and tag name, which are only relevant parts of an XML or HTML tag and attribute name respectively.

In lieu of our XML Namespace example

<furn:table> <!-- namespace url is https://furniture.rs -->

For it the expanded name would become roughly equivalent to:

ExpandedName {
   ns: "https://furniture.rs",
   local: "table",
}

Trait Implementations§

source§

impl Clone for QualName

source§

fn clone(&self) -> QualName

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for QualName

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
source§

impl<'a> ElemName for &'a QualName

source§

impl Hash for QualName

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for QualName

source§

fn cmp(&self, other: &QualName) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for QualName

source§

fn eq(&self, other: &QualName) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

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

impl PartialOrd for QualName

source§

fn partial_cmp(&self, other: &QualName) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

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

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 more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

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

fn ge(&self, other: &Rhs) -> bool

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

impl Eq for QualName

source§

impl StructuralPartialEq for QualName

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

source§

const WITNESS: W = W::MAKE

A constant of the type witness
source§

impl<T> Identity for T
where T: ?Sized,

§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more