pub struct Name(/* private fields */);Expand description
String slice for Name.
Implementations§
Source§impl Name
impl Name
Sourcepub unsafe fn new_unchecked(s: &str) -> &Self
pub unsafe fn new_unchecked(s: &str) -> &Self
Sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
Returns the string as &str.
§Examples
let name = Name::from_str("hello")?;
assert_eq!(name, "hello");
let s: &str = name.as_str();
assert_eq!(s, "hello");Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length of the string in bytes.
§Examples
let name = Name::from_str("foo:bar")?;
assert_eq!(name.len(), 7);Sourcepub fn parse_next(s: &str) -> Result<(&Self, &str), NameError>
pub fn parse_next(s: &str) -> Result<(&Self, &str), NameError>
Parses the leading Name and returns the value and the rest input.
§Exmaples
let input = "hello, world";
let expected = Name::from_str("hello").expect("valid Name");
assert_eq!(
Name::parse_next(input),
Ok((expected, ", world"))
);let input = "012";
assert!(Name::parse_next(input).is_err());Sourcepub fn into_boxed_str(self: Box<Self>) -> Box<str>
pub fn into_boxed_str(self: Box<Self>) -> Box<str>
Converts a Box<Name> into a Box<str> without copying or allocating.
§Examples
let name = Name::from_str("name")?;
let boxed_name: Box<Name> = name.into();
assert_eq!(&*boxed_name, name);
let boxed_str: Box<str> = boxed_name.into_boxed_str();
assert_eq!(&*boxed_str, name.as_str());