Skip to main content

Name

Struct Name 

Source
pub struct Name { /* private fields */ }
Expand description

An element or attribute name as the author wrote it.

A Name is a prefix and a local part, not a resolved name: the prefix is looked up when the document is built, against the form’s own declarations first and the composer’s namespace table second. An empty prefix on an element takes the composer’s default element namespace; an empty prefix on an attribute means no namespace, as Namespaces in XML 1.0 §6.2 requires.

use xsd_schema::compose::Name;

assert_eq!(Name::local("item").to_string(), "item");
assert_eq!(Name::prefixed("p", "item").to_string(), "p:item");
assert_eq!(Name::parse("p:item")?.prefix(), "p");
assert!(Name::parse("not a name").is_err());

Implementations§

Source§

impl Name

Source

pub fn local(local: &str) -> Self

A name with no prefix.

use xsd_schema::compose::Name;

let n = Name::local("high_bid");
assert_eq!(n.prefix(), "");
assert_eq!(n.local_name(), "high_bid");
Source

pub fn prefixed(prefix: &str, local: &str) -> Self

A name with a prefix to resolve at build time.

use xsd_schema::compose::Name;

let n = Name::prefixed("xml", "lang");
assert_eq!(n.prefix(), "xml");
assert_eq!(n.local_name(), "lang");
Source

pub fn parse(text: &str) -> Result<Self, ComposeError>

Parses local or prefix:local, checking both halves are NCNames.

use xsd_schema::compose::{ComposeError, Name};

assert_eq!(Name::parse("bid-count")?.local_name(), "bid-count");
assert_eq!(Name::parse("p:bid")?.prefix(), "p");
assert!(matches!(Name::parse("a:b:c"), Err(ComposeError::InvalidName(_))));
assert!(matches!(Name::parse(""), Err(ComposeError::InvalidName(_))));
Source

pub fn prefix(&self) -> &str

The prefix, empty when there is none.

use xsd_schema::compose::Name;

assert_eq!(Name::prefixed("p", "a").prefix(), "p");
assert_eq!(Name::local("a").prefix(), "");
Source

pub fn local_name(&self) -> &str

The local part.

use xsd_schema::compose::Name;

assert_eq!(Name::prefixed("p", "a").local_name(), "a");

Trait Implementations§

Source§

impl Clone for Name

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for Name

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 Eq for Name

Source§

impl Hash for Name

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

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Name

Auto Trait Implementations§

§

impl Forget for Name

§

impl Freeze for Name
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze,

§

impl Move for Name

§

impl RefUnwindSafe for Name

§

impl Send for Name
where RawVecInner: Send,

§

impl Sync for Name
where RawVecInner: Sync,

§

impl Unpin for Name
where *const u8 is !null: Unpin,

§

impl UnsafeUnpin for Name

§

impl UnwindSafe for Name
where RawVecInner: UnwindSafe,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

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

Source§

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

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

impl<T> ErasedDestructor for T
where T: 'static,

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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§

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.