[][src]Struct xml_string::names::Ncname

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

String slice for NCName.

Implementations

impl Ncname[src]

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

Creates a new &Ncname.

Failures

Fails if the given string is not a valid NCName.

Examples

let name = Ncname::from_str("hello")?;
assert_eq!(name, "hello");

assert!(Ncname::from_str("").is_err(), "Empty string is not an NCName");
assert!(Ncname::from_str("foo bar").is_err(), "Whitespace is not allowed");
assert!(Ncname::from_str("foo:bar").is_err(), "Colon is not allowed");
assert!(Ncname::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 &Ncname without validation.

Safety

The given string should be a valid NCName.

Examples

let name = unsafe {
    Ncname::new_unchecked("hello")
};
assert_eq!(name, "hello");

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

Returns the string as &str.

Examples

let name = Ncname::from_str("hello")?;
assert_eq!(name, "hello");

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

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

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

Exmaples

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

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

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

Examples

let name = Ncname::from_str("ncname")?;
let boxed_name: Box<Ncname> = 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 Ncname[src]

impl AsRef<Ncname> for Ncname[src]

impl AsRef<Nmtoken> for Ncname[src]

impl AsRef<Qname> for Ncname[src]

impl AsRef<str> for Ncname[src]

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

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

impl Eq for Ncname[src]

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

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

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

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

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

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

impl Hash for Ncname[src]

impl Ord for Ncname[src]

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

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

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

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

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

impl PartialEq<Ncname> for Ncname[src]

impl PartialEq<Ncname> for str[src]

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

impl PartialEq<Ncname> for String[src]

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

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

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

impl PartialEq<String> for Ncname[src]

impl PartialEq<str> for Ncname[src]

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

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

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

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

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

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

impl PartialOrd<Ncname> for Ncname[src]

impl PartialOrd<Ncname> for str[src]

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

impl PartialOrd<Ncname> for String[src]

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

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

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

impl PartialOrd<String> for Ncname[src]

impl PartialOrd<str> for Ncname[src]

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

impl StructuralEq for Ncname[src]

impl StructuralPartialEq for Ncname[src]

impl ToOwned for Ncname[src]

type Owned = Box<Ncname>

The resulting type after obtaining ownership.

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

type Error = NameError

The type returned in the event of a conversion error.

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 Ncname[src]

type Error = NameError

The type returned in the event of a conversion error.

Auto Trait Implementations

impl RefUnwindSafe for Ncname

impl Send for Ncname

impl Sync for Ncname

impl Unpin for Ncname

impl UnwindSafe for Ncname

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]