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
impl Name
Sourcepub fn local(local: &str) -> Self
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");Sourcepub fn prefixed(prefix: &str, local: &str) -> Self
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");Sourcepub fn parse(text: &str) -> Result<Self, ComposeError>
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(_))));Sourcepub fn prefix(&self) -> &str
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(), "");Sourcepub fn local_name(&self) -> &str
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§
impl Eq for Name
impl StructuralPartialEq for Name
Auto Trait Implementations§
impl Forget for Name
impl Freeze for Name
impl Move for Name
impl RefUnwindSafe for Name
impl Send for Namewhere
RawVecInner: Send,
impl Sync for Namewhere
RawVecInner: Sync,
impl Unpin for Name
impl UnsafeUnpin for Name
impl UnwindSafe for Namewhere
RawVecInner: UnwindSafe,
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
Mutably borrows from an owned value. Read more