Enum Name

Source
pub enum Name {
    Named(Cow<'static, str>),
    Unnamed {
        id: usize,
        ext: Option<Cow<'static, str>>,
    },
}
Expand description

Type that represents a name of a XSD element

Variants§

§

Named(Cow<'static, str>)

The name was explicitly set to the given value.

§

Unnamed

The name is unknown and should be generated out of the provided information.

Fields

§id: usize

Unique id for this name.

§ext: Option<Cow<'static, str>>

Extension that may be added to the name.

Implementations§

Source§

impl Name

Source

pub const fn named(name: &'static str) -> Self

Create a new Name::Named using the passed name.

Source

pub fn new<S: Into<String>>(name: S) -> Self

Create a new Name::Named using the passed name.

Source

pub fn remove_suffix(&self, suffix: &str) -> Self

Remove the provided suffix from the Name::Named or the Name::Unnamed::ext

§Examples
let name = Name::new("test-fuu");
let expected = Name::new("test");
assert_eq!(name.remove_suffix("-fuu"), expected);

let name = Name::Unnamed { id: 123, ext: Some(Cow::Borrowed("test-fuu")) };
let expected = Name::Unnamed { id: 123, ext: Some(Cow::Owned("test".into())) };;
assert_eq!(name.remove_suffix("-fuu"), expected);
Source

pub fn to_type_name(&self, with_id: bool, name: Option<&str>) -> Self

Create a type name from this Name object.

This method can be used to generate a rust type name from this name object. The resulting name is written in pascal case and may or may not contain additional information depending on the passed arguments.

§Arguments
  • with_id Wether to add the unique id of the name to the resulting name or not
  • name Optional name that should be added to the resulting name
§Examples

let name = Name::new("test");
assert_eq!(Name::new("Test"), name.to_type_name(false, None));
assert_eq!(Name::new("Test"), name.to_type_name(true, None));
assert_eq!(Name::new("Test"), name.to_type_name(false, Some("extra")));
assert_eq!(Name::new("Test"), name.to_type_name(true, Some("extra")));

let name = Name::Unnamed { id: 123, ext: None };
assert_eq!(Name::new("Unnamed123"), name.to_type_name(false, None));
assert_eq!(Name::new("Extra"), name.to_type_name(false, Some("extra")));
assert_eq!(Name::new("Unnamed123"), name.to_type_name(true, None));
assert_eq!(Name::new("Extra123"), name.to_type_name(true, Some("extra")));

let name = Name::Unnamed { id: 123, ext: Some(Cow::Borrowed("ext")) };
assert_eq!(Name::new("ExtUnnamed123"), name.to_type_name(false, None));
assert_eq!(Name::new("ExtExtra"), name.to_type_name(false, Some("extra")));
assert_eq!(Name::new("ExtUnnamed123"), name.to_type_name(true, None));
assert_eq!(Name::new("ExtExtra123"), name.to_type_name(true, Some("extra")));
Source

pub fn is_named(&self) -> bool

Returns true if this is a Name::Named, false otherwise.

Source

pub fn is_unnamed(&self) -> bool

Returns true if this is a Name::Unnamed, false otherwise.

Source

pub fn has_extension(&self) -> bool

Returns true if this is a Name::Unnamed with extensions, false otherwise.

Source

pub fn as_str(&self) -> Option<&str>

Returns the value of Name::Named as Some(&str), or None if it’s an Name::Unnamed.

Source

pub fn extend<I>(self, replace: bool, iter: I) -> Self
where I: IntoIterator, I::Item: Display,

Adds extensions to this name.

§Arguments
  • replace replace any existing extension with the new one
  • iter iterator of extensions to apply
§Examples

let name = Name::new("test");
assert_eq!(Name::new("extTest"), name.extend(false, Some("ext")));

let name = Name::Unnamed { id: 123, ext: Some(Cow::Borrowed("ext")) };
assert_eq!(Name::Unnamed { id: 123, ext: Some(Cow::Owned("fuu".into())) }, name.clone().extend(true, Some("fuu")));
assert_eq!(Name::Unnamed { id: 123, ext: Some(Cow::Owned("fuuExt".into())) }, name.extend(false, Some("fuu")));

Trait Implementations§

Source§

impl Clone for Name

Source§

fn clone(&self) -> Name

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 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<'_>) -> FmtResult

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

impl From<&'static str> for Name

Source§

fn from(value: &'static str) -> Self

Converts to this type from the input type.
Source§

impl From<String> for Name

Source§

fn from(value: String) -> Self

Converts to this type from the input type.
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 Ord for Name

Source§

fn cmp(&self, other: &Name) -> 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,

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

impl PartialEq for Name

Source§

fn eq(&self, other: &Name) -> 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 PartialOrd for Name

Source§

fn partial_cmp(&self, other: &Name) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for Name

Source§

impl StructuralPartialEq for Name

Auto Trait Implementations§

§

impl Freeze for Name

§

impl RefUnwindSafe for Name

§

impl Send for Name

§

impl Sync for Name

§

impl Unpin for Name

§

impl UnwindSafe for Name

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<X> AsAny for X
where X: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Get a reference to the current object as Any.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Get a mutable reference to the current object as Any.
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> 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<X> SerializeBytes for X
where X: ToString,

Source§

fn serialize_bytes(&self) -> Result<Option<Cow<'_, str>>, Error>

Try to serialize the type to bytes. Read more
Source§

impl<X> SerializeSync for X
where X: WithSerializer,

Source§

type Error = Error

Error returned by the serialize method.
Source§

fn serialize<W>( &self, root: &str, writer: &mut Writer<W>, ) -> Result<(), <X as SerializeSync>::Error>
where W: Write,

Serializes the type to XML using the provided writer. Read more
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 = 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<X> WithBoxedSerializer for X
where X: WithSerializer,

Source§

fn serializer<'ser>( &'ser self, name: Option<&'ser str>, is_root: bool, ) -> Result<Box<dyn Serializer<'ser, Item = Result<Event<'ser>, Error>> + 'ser>, Error>

Initializes a new serializer from the passed value. Read more
Source§

impl<X> WithSerializer for X
where X: SerializeBytes + Debug,

Source§

type Serializer<'x> = ContentSerializer<'x, X> where X: 'x

The serializer to use for this type.
Source§

fn serializer<'ser>( &'ser self, name: Option<&'ser str>, is_root: bool, ) -> Result<<X as WithSerializer>::Serializer<'ser>, Error>

Initializes a new serializer from the passed value. Read more
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
Source§

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

Source§

impl<T> MaybeSendSync for T