xml::name

Struct Name

Source
pub struct Name<'a> {
    pub local_name: &'a str,
    pub namespace: Option<&'a str>,
    pub prefix: Option<&'a str>,
}
Expand description

Represents a qualified XML name.

A qualified name always consists at least of a local name. It can optionally contain a prefix; when reading an XML document, if it contains a prefix, it must also contain a namespace URI, but this is not enforced statically; see below. The name can contain a namespace without a prefix; in that case a default, empty prefix is assumed.

When writing XML documents, it is possible to omit the namespace URI, leaving only the prefix. In this case the writer will check that the specifed prefix is bound to some URI in the current namespace context. If both prefix and namespace URI are specified, it is checked that the current namespace context contains this exact correspondence between prefix and namespace URI.

§Prefixes and URIs

A qualified name with a prefix must always contain a proper namespace URI — names with a prefix but without a namespace associated with that prefix are meaningless. However, it is impossible to obtain proper namespace URI by a prefix without a context, and such context is only available when parsing a document (or it can be constructed manually when writing a document). Tying a name to a context statically seems impractical. This may change in future, though.

§Conversions

Name implements some From instances for conversion from strings and tuples. For example:

let n1: Name = "p:some-name".into();
let n2: Name = ("p", "some-name").into();

assert_eq!(n1, n2);
assert_eq!(n1.local_name, "some-name");
assert_eq!(n1.prefix, Some("p"));
assert!(n1.namespace.is_none());

This is added to support easy specification of XML elements when writing XML documents.

Fields§

§local_name: &'a str

A local name, e.g. string in xsi:string.

§namespace: Option<&'a str>

A namespace URI, e.g. http://www.w3.org/2000/xmlns/.

§prefix: Option<&'a str>

A name prefix, e.g. xsi in xsi:string.

Implementations§

Source§

impl<'a> Name<'a>

Source

pub fn to_owned(&self) -> OwnedName

Returns an owned variant of the qualified name.

Source

pub const fn local(local_name: &str) -> Name<'_>

Returns a new Name instance representing plain local name.

Source

pub const fn prefixed(local_name: &'a str, prefix: &'a str) -> Self

Returns a new Name instance with the given local name and prefix.

Source

pub const fn qualified( local_name: &'a str, namespace: &'a str, prefix: Option<&'a str>, ) -> Self

Returns a new Name instance representing a qualified name with or without a prefix and with a namespace URI.

Source

pub fn to_repr(&self) -> String

Returns a correct XML representation of this local name and prefix.

This method is different from the autoimplemented to_string() because it does not include namespace URI in the result.

Source

pub const fn repr_display(&self) -> ReprDisplay<'_, '_>

Returns a structure which can be displayed with std::fmt machinery to obtain this local name and prefix.

This method is needed for efficiency purposes in order not to create unnecessary allocations.

Source

pub fn prefix_repr(&self) -> &str

Returns either a prefix of this name or namespace::NS_NO_PREFIX constant.

Trait Implementations§

Source§

impl<'a> Clone for Name<'a>

Source§

fn clone(&self) -> Name<'a>

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<'a> Debug for Name<'a>

Source§

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

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

impl Display for Name<'_>

Source§

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

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

impl<'a> From<&'a str> for Name<'a>

Source§

fn from(s: &'a str) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<(&'a str, &'a str)> for Name<'a>

Source§

fn from((prefix, name): (&'a str, &'a str)) -> Self

Converts to this type from the input type.
Source§

impl<'a> From<Name<'a>> for OwnedName

Source§

fn from(n: Name<'a>) -> Self

Converts to this type from the input type.
Source§

impl<'a> Hash for Name<'a>

Source§

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

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<'a> PartialEq for Name<'a>

Source§

fn eq(&self, other: &Name<'a>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'a> Copy for Name<'a>

Source§

impl<'a> Eq for Name<'a>

Source§

impl<'a> StructuralPartialEq for Name<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Name<'a>

§

impl<'a> RefUnwindSafe for Name<'a>

§

impl<'a> Send for Name<'a>

§

impl<'a> Sync for Name<'a>

§

impl<'a> Unpin for Name<'a>

§

impl<'a> UnwindSafe for Name<'a>

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§

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

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

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>,

Source§

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.