Name

Struct Name 

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

An owned name stores the name, namespace and prefix as owned strings.

An owned name is handy when you don’t want to depend on Xot, or for debugging.

It cannot be used to create elements directly, but you can turn this into a CreateName using OwnedName::to_create and a RefName using OwnedName::to_ref.

You can access name string information using the NameStrInfo trait.

If you enable the serde feature it can be serialized and deserialized.

Implementations§

Source§

impl OwnedName

Source

pub fn new(local_name: String, namespace: String, prefix: String) -> OwnedName

Create a new owned name.

Source

pub fn name(local_name: &str) -> OwnedName

Create a name without a namespace

Source

pub fn namespaced( local_name: String, namespace: String, prefix_lookup: impl Fn(&str) -> Option<String>, ) -> Result<OwnedName, Error>

Create a new name in a namespace, look up prefix information.

Source

pub fn prefixed( prefix: &str, local_name: &str, lookup_namespace: impl Fn(&str) -> Option<String>, ) -> Result<OwnedName, Error>

Create a new owned name from a prefix and a name.

Source

pub fn parse_full_name( full_name: &str, lookup_namespace: impl Fn(&str) -> Option<String>, ) -> Result<OwnedName, Error>

Given a fullname (with potentially a prefix), construct an XmlNameOwned

This requires a function that can look up the namespace for a prefix.

Source

pub fn with_suffix(self) -> OwnedName

Convert this name into a name adding a * suffix.

This can be useful to help generate unique names.

Source

pub fn with_default_namespace(self, namespace: &str) -> OwnedName

Convert this name into a name that’s in a particular namespace.

This only changes the namespace if there is an empty prefix and the namespace is not set (the empty string).

Source

pub fn in_default_namespace(&self) -> bool

Name is in a namespace but without a prefix, so it’s in a default namespace.

Source

pub fn to_ref<'a>(&self, xot: &'a mut Xot) -> RefName<'a>

Create a new RefName from this owned name.

Source

pub fn maybe_to_ref<'a>(&self, xot: &'a Xot) -> Option<RefName<'a>>

Create a new RefName only if names already exists in Xot.

If the local name and namespace don’t exist in Xot, returns None.

This lets you pass in an immutable reference to Xot, unlike Owned::to_ref.

Ignores prefix information - even if the prefix doesn’t exist, we still get a ref name, just without a prefix. This is because the prefix information is irrelevant for comparison.

Otherwise, returns None.

Source

pub fn to_create(&self, xot: &mut Xot) -> CreateName

Create a new CreateName name from this owned name.

This disregards the prefix information.

Trait Implementations§

Source§

impl Clone for OwnedName

Source§

fn clone(&self) -> OwnedName

Returns a duplicate 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 OwnedName

Source§

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

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

impl From<OwnedName> for Atomic

Source§

fn from(n: OwnedName) -> Atomic

Converts to this type from the input type.
Source§

impl Hash for OwnedName

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 NameStrInfo for OwnedName

Source§

fn local_name(&self) -> &str

Access the local name as a string reference
Source§

fn namespace(&self) -> &str

Get the namespace uri as a str reference. Read more
Source§

fn prefix(&self) -> &str

Access the prefix as a string
Source§

fn full_name(&self) -> Cow<'_, str>

Access the full name as a string
Source§

impl PartialEq for OwnedName

Source§

fn eq(&self, other: &OwnedName) -> 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 TryFrom<Atomic> for OwnedName

Source§

type Error = Error

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

fn try_from( a: Atomic, ) -> Result<OwnedName, <OwnedName as TryFrom<Atomic>>::Error>

Performs the conversion.
Source§

impl WithSpan for OwnedName

Source§

fn with_span(self, span: SimpleSpan) -> Spanned<Self>

Source§

fn with_empty_span(self) -> Spanned<Self>

Source§

impl Eq for OwnedName

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§

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<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, 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<'src, T> IntoMaybe<'src, T> for T
where T: 'src,

Source§

type Proj<U: 'src> = U

Source§

fn map_maybe<R>( self, _f: impl FnOnce(&'src T) -> &'src R, g: impl FnOnce(T) -> R, ) -> <T as IntoMaybe<'src, T>>::Proj<R>
where R: 'src,

Source§

impl<'p, T> Seq<'p, T> for T
where T: Clone,

Source§

type Item<'a> = &'a T where T: 'a

The item yielded by the iterator.
Source§

type Iter<'a> = Once<&'a T> where T: 'a

An iterator over the items within this container, by reference.
Source§

fn seq_iter(&self) -> <T as Seq<'p, T>>::Iter<'_>

Iterate over the elements of the container.
Source§

fn contains(&self, val: &T) -> bool
where T: PartialEq,

Check whether an item is contained within this sequence.
Source§

fn to_maybe_ref<'b>(item: <T as Seq<'p, T>>::Item<'b>) -> Maybe<T, &'p T>
where 'p: 'b,

Convert an item of the sequence into a MaybeRef.
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, 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.
Source§

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

Source§

impl<T> MaybeSendSync for T

Source§

impl<T> OrderedSeq<'_, T> for T
where T: Clone,