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.
Implementations§
Source§impl Name
impl Name
Sourcepub const fn named(name: &'static str) -> Self
pub const fn named(name: &'static str) -> Self
Create a new Name::Named using the passed name.
Sourcepub fn new<S: Into<String>>(name: S) -> Self
pub fn new<S: Into<String>>(name: S) -> Self
Create a new Name::Named using the passed name.
Sourcepub fn remove_suffix(&self, suffix: &str) -> Self
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);Sourcepub fn to_type_name(&self, with_id: bool, name: Option<&str>) -> Self
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_idWether to add the unique id of the name to the resulting name or notnameOptional 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")));Sourcepub fn is_named(&self) -> bool
pub fn is_named(&self) -> bool
Returns true if this is a Name::Named, false otherwise.
Sourcepub fn is_unnamed(&self) -> bool
pub fn is_unnamed(&self) -> bool
Returns true if this is a Name::Unnamed, false otherwise.
Sourcepub fn has_extension(&self) -> bool
pub fn has_extension(&self) -> bool
Returns true if this is a Name::Unnamed with extensions, false otherwise.
Sourcepub fn as_str(&self) -> Option<&str>
pub fn as_str(&self) -> Option<&str>
Returns the value of Name::Named as Some(&str), or None if it’s an Name::Unnamed.
Sourcepub fn extend<I>(self, replace: bool, iter: I) -> Self
pub fn extend<I>(self, replace: bool, iter: I) -> Self
Adds extensions to this name.
§Arguments
replacereplace any existing extension with the new oneiteriterator 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 Ord for Name
impl Ord for Name
Source§impl PartialOrd for Name
impl PartialOrd for Name
impl Eq for Name
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<X> SerializeBytes for Xwhere
X: ToString,
impl<X> SerializeBytes for Xwhere
X: ToString,
Source§impl<X> SerializeSync for Xwhere
X: WithSerializer,
impl<X> SerializeSync for Xwhere
X: WithSerializer,
Source§impl<X> WithBoxedSerializer for Xwhere
X: WithSerializer,
impl<X> WithBoxedSerializer for Xwhere
X: WithSerializer,
Source§impl<X> WithSerializer for Xwhere
X: SerializeBytes + Debug,
impl<X> WithSerializer for Xwhere
X: SerializeBytes + Debug,
Source§type Serializer<'x> = ContentSerializer<'x, X>
where
X: 'x
type Serializer<'x> = ContentSerializer<'x, X> where X: 'x
Source§fn serializer<'ser>(
&'ser self,
name: Option<&'ser str>,
is_root: bool,
) -> Result<<X as WithSerializer>::Serializer<'ser>, Error>
fn serializer<'ser>( &'ser self, name: Option<&'ser str>, is_root: bool, ) -> Result<<X as WithSerializer>::Serializer<'ser>, Error>
value. Read more