[][src]Struct xml_string::names::Qname

#[repr(transparent)]pub struct Qname(_);

String slice for QName.

Implementations

impl Qname[src]

pub fn from_str(s: &str) -> Result<&Self, NameError>[src]

Creates a new &Qname.

Failures

Fails if the given string is not a valid QName.

Examples

let noprefix = Qname::from_str("hello")?;
assert_eq!(noprefix, "hello");

let prefixed = Qname::from_str("foo:bar")?;
assert_eq!(prefixed, "foo:bar");

assert!(Qname::from_str("").is_err(), "Empty string is not a QName");
assert!(Qname::from_str("foo bar").is_err(), "Whitespace is not allowed");
assert!(Qname::from_str("foo:bar:baz").is_err(), "Two or more colons are not allowed");
assert!(Qname::from_str("0foo").is_err(), "ASCII digit at the beginning is not allowed");

#[must_use]pub unsafe fn new_unchecked(s: &str) -> &Self[src]

Creates a new &Qname without validation.

Safety

The given string should be a valid QName.

Examples

let name = unsafe {
    Qname::new_unchecked("foo:bar")
};
assert_eq!(name, "foo:bar");

#[must_use]pub fn as_str(&self) -> &str[src]

Returns the string as &str.

Examples

let name = Qname::from_str("foo:bar")?;
assert_eq!(name, "foo:bar");

let s: &str = name.as_str();
assert_eq!(s, "foo:bar");

pub fn parse_next(s: &str) -> Result<(&Self, &str), NameError>[src]

Parses the leading Qname and returns the value and the rest input.

Exmaples

let input = "hello:012";
let expected = Qname::from_str("hello").expect("valid Qname");
assert_eq!(
    Qname::parse_next(input),
    Ok((expected, ":012"))
);
let input = "hello:world:foo";
let expected = Qname::from_str("hello:world").expect("valid Qname");
assert_eq!(
    Qname::parse_next(input),
    Ok((expected, ":foo"))
);
let input = "012";
assert!(Qname::parse_next(input).is_err());

#[must_use]pub fn has_prefix(&self) -> bool[src]

Returns whether the QName has a prefix.

Note that this is O(length) operation. Consider using ParsedQname::has_prefix method if possible.

Examples

let local_only = Qname::from_str("hello")?;
assert!(!local_only.has_prefix());

let prefixed = Qname::from_str("foo:bar")?;
assert!(prefixed.has_prefix());

#[must_use]pub fn prefix(&self) -> Option<&Ncname>[src]

Returns the prefix if available.

Note that this is O(length) operation. Consider using ParsedQname::prefix method if possible.

Examples

let prefixed = Qname::from_str("foo:bar")?;
assert_eq!(prefixed.prefix().map(|s| s.as_str()), Some("foo"));

let noprefix = Qname::from_str("foo")?;
assert_eq!(noprefix.prefix().map(|s| s.as_str()), None);

#[must_use]pub fn local_part(&self) -> &Ncname[src]

Returns the local part.

Note that this is O(length) operation. Consider using ParsedQname::local_part method if possible.

Examples

let prefixed = Qname::from_str("foo:bar")?;
assert_eq!(prefixed.local_part(), "bar");

let noprefix = Qname::from_str("foo")?;
assert_eq!(noprefix.local_part(), "foo");

#[must_use]pub fn prefix_and_local(&self) -> (Option<&Ncname>, &Ncname)[src]

Returns a pair of the prefix (if available) and the local part.

Note that this is O(length) operation. Consider using ParsedQname::prefix_and_local method if possible.

Examples

use std::convert::TryFrom;

let noprefix = Qname::from_str("hello")?;
assert_eq!(noprefix.prefix_and_local(), (noprefix.prefix(), noprefix.local_part()));

let prefixed = Qname::from_str("foo:bar")?;
assert_eq!(prefixed.prefix_and_local(), (prefixed.prefix(), prefixed.local_part()));

pub fn into_boxed_str(self: Box<Self>) -> Box<str>[src]

Converts a Box<Qname> into a Box<str> without copying or allocating.

Examples

let name = Qname::from_str("q:name")?;
let boxed_name: Box<Qname> = name.into();
assert_eq!(&*boxed_name, name);
let boxed_str: Box<str> = boxed_name.into_boxed_str();
assert_eq!(&*boxed_str, name.as_str());

Trait Implementations

impl AsRef<Name> for Qname[src]

impl AsRef<Nmtoken> for Qname[src]

impl AsRef<Qname> for Ncname[src]

impl AsRef<Qname> for Qname[src]

impl<'_> AsRef<Qname> for ParsedQname<'_>[src]

impl AsRef<str> for Qname[src]

impl<'_> Debug for &'_ Qname[src]

impl<'_> Display for &'_ Qname[src]

impl Eq for Qname[src]

impl<'_> From<&'_ Qname> for Box<Qname>[src]

impl<'_> From<&'_ Qname> for Rc<Qname>[src]

impl<'_> From<&'_ Qname> for Arc<Qname>[src]

impl<'a> From<&'a Ncname> for &'a Qname[src]

impl<'a> From<&'a Qname> for &'a Name[src]

impl<'a> From<&'a Qname> for &'a Nmtoken[src]

impl<'a> From<&'a Qname> for ParsedQname<'a>[src]

impl<'a> From<ParsedQname<'a>> for &'a Qname[src]

impl Hash for Qname[src]

impl Ord for Qname[src]

impl<'_> PartialEq<&'_ Qname> for str[src]

impl<'_> PartialEq<&'_ String> for Qname[src]

impl<'_> PartialEq<&'_ str> for Qname[src]

impl PartialEq<Box<str, Global>> for Qname[src]

impl<'_> PartialEq<Cow<'_, str>> for Qname[src]

impl PartialEq<Qname> for Qname[src]

impl PartialEq<Qname> for str[src]

impl<'_> PartialEq<Qname> for &'_ str[src]

impl PartialEq<Qname> for String[src]

impl<'_> PartialEq<Qname> for &'_ String[src]

impl PartialEq<Qname> for Box<str>[src]

impl<'_> PartialEq<Qname> for Cow<'_, str>[src]

impl PartialEq<String> for Qname[src]

impl PartialEq<str> for Qname[src]

impl<'_> PartialEq<str> for &'_ Qname[src]

impl<'_> PartialOrd<&'_ Qname> for str[src]

impl<'_> PartialOrd<&'_ String> for Qname[src]

impl<'_> PartialOrd<&'_ str> for Qname[src]

impl PartialOrd<Box<str, Global>> for Qname[src]

impl<'_> PartialOrd<Cow<'_, str>> for Qname[src]

impl PartialOrd<Qname> for Qname[src]

impl PartialOrd<Qname> for str[src]

impl<'_> PartialOrd<Qname> for &'_ str[src]

impl PartialOrd<Qname> for String[src]

impl<'_> PartialOrd<Qname> for &'_ String[src]

impl PartialOrd<Qname> for Box<str>[src]

impl<'_> PartialOrd<Qname> for Cow<'_, str>[src]

impl PartialOrd<String> for Qname[src]

impl PartialOrd<str> for Qname[src]

impl<'_> PartialOrd<str> for &'_ Qname[src]

impl StructuralEq for Qname[src]

impl StructuralPartialEq for Qname[src]

impl ToOwned for Qname[src]

type Owned = Box<Qname>

The resulting type after obtaining ownership.

impl<'a> TryFrom<&'a Qname> for &'a Ncname[src]

type Error = NameError

The type returned in the event of a conversion error.

impl<'a> TryFrom<&'a str> for &'a Qname[src]

type Error = NameError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Qname

impl Send for Qname

impl Sync for Qname

impl Unpin for Qname

impl UnwindSafe for Qname

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]