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_named(&self, with_id: bool, name: Option<&str>) -> Self
pub fn to_type_named(&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_named(false, None));
assert_eq!(Name::new("Test"), name.to_type_named(true, None));
assert_eq!(Name::new("Test"), name.to_type_named(false, Some("extra")));
assert_eq!(Name::new("Test"), name.to_type_named(true, Some("extra")));
let name = Name::Unnamed { id: 123, ext: None };
assert_eq!(Name::new("Unnamed123"), name.to_type_named(false, None));
assert_eq!(Name::new("Extra"), name.to_type_named(false, Some("extra")));
assert_eq!(Name::new("Unnamed123"), name.to_type_named(true, None));
assert_eq!(Name::new("Extra123"), name.to_type_named(true, Some("extra")));
let name = Name::Unnamed { id: 123, ext: Some(Cow::Borrowed("ext")) };
assert_eq!(Name::new("ExtUnnamed123"), name.to_type_named(false, None));
assert_eq!(Name::new("ExtExtra"), name.to_type_named(false, Some("extra")));
assert_eq!(Name::new("ExtUnnamed123"), name.to_type_named(true, None));
assert_eq!(Name::new("ExtExtra123"), name.to_type_named(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")));