Struct ascii::AsciiStr
[−]
[src]
pub struct AsciiStr {
// some fields omitted
}A borrowed ascii string, like a slice into an AsciiString.
Methods
impl AsciiStr[src]
fn new<S: AsRef<AsciiStr> + ?Sized>(s: &S) -> &AsciiStr
Coerces into an AsciiStr slice.
fn as_str(&self) -> &str
Converts &self to a &str slice.
fn to_ascii_string(&self) -> AsciiString
Copies the content of this AsciiStr into an owned AsciiString.
fn as_bytes(&self) -> &[u8]
Converts &self into a byte slice.
fn from_bytes<'a, B: ?Sized>(bytes: &'a B) -> Option<&'a AsciiStr> where B: AsRef<[u8]>
Converts anything that can represent a byte slice into an AsciiStr.
Failure
Returns None if the byte slice can not be ascii encoded.
Examples
let foo = AsciiStr::from_bytes("foo").unwrap(); let err = AsciiStr::from_bytes("Ŋ"); assert_eq!(foo.as_str(), "foo"); assert_eq!(err, None);
fn from_str<'a>(s: &'a str) -> Option<&'a AsciiStr>
Converts a borrowed string to a borrows ascii string.
Failure
Returns None if the byte slice can not be ascii encoded.
fn len(&self) -> usize
Returns the number of bytes in this ascii string.
Examples
let s = AsciiStr::from_bytes("foo").unwrap(); assert_eq!(s.len(), 3);
fn is_empty(&self) -> bool
Returns true if the ascii string contains no bytes.
Examples
let mut empty = AsciiStr::from_bytes("").unwrap(); let mut full = AsciiStr::from_bytes("foo").unwrap(); assert!(empty.is_empty()); assert!(!full.is_empty());
fn trim(&self) -> &Self
Returns an ascii string slice with leading and trailing whitespace removed.
Examples
let example = AsciiStr::from_str(" \twhite \tspace \t").unwrap(); assert_eq!("white \tspace", example.trim());
fn trim_left(&self) -> &Self
Returns a string slice with leading whitespace removed.
Examples
let example = AsciiStr::from_str(" \twhite \tspace \t").unwrap(); assert_eq!("white \tspace \t", example.trim_left());
fn trim_right(&self) -> &Self
Returns a string slice with trainling whitespace removed.
Examples
let example = AsciiStr::from_str(" \twhite \tspace \t").unwrap(); assert_eq!(" \twhite \tspace", example.trim_right());
Trait Implementations
impl Hash for AsciiStr[src]
fn hash<__H: Hasher>(&self, __arg_0: &mut __H)
Feeds this value into the state given, updating the hasher as necessary.
fn hash_slice<H>(data: &[Self], state: &mut H) where H: Hasher1.3.0
Feeds a slice of this type into the state provided.
impl PartialEq for AsciiStr[src]
fn eq(&self, other: &AsciiStr) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0
This method tests for !=.
impl Eq for AsciiStr[src]
impl PartialOrd for AsciiStr[src]
fn partial_cmp(&self, other: &AsciiStr) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &AsciiStr) -> bool
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &AsciiStr) -> bool
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &AsciiStr) -> bool
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &AsciiStr) -> bool
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl Ord for AsciiStr[src]
fn cmp(&self, other: &AsciiStr) -> Ordering
This method returns an Ordering between self and other. Read more
impl ToOwned for AsciiStr[src]
type Owned = AsciiString
fn to_owned(&self) -> AsciiString
Creates owned data from borrowed data, usually by cloning. Read more
impl AsRef<[u8]> for AsciiStr[src]
impl AsRef<str> for AsciiStr[src]
impl Display for AsciiStr[src]
impl Debug for AsciiStr[src]
impl<'a> PartialEq<String> for &'a AsciiStr[src]
fn eq(&self, other: &String) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &String) -> bool
This method tests for !=.
impl<'a> PartialEq<AsciiString> for &'a AsciiStr[src]
fn eq(&self, other: &AsciiString) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &AsciiString) -> bool
This method tests for !=.
impl PartialEq<str> for AsciiStr[src]
fn eq(&self, other: &str) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0
This method tests for !=.
impl Index<usize> for AsciiStr[src]
type Output = Ascii
The returned type after indexing
fn index(&self, index: usize) -> &Ascii
The method for the indexing (Foo[Bar]) operation
impl IndexMut<usize> for AsciiStr[src]
fn index_mut(&mut self, index: usize) -> &mut Ascii
The method for the indexing (Foo[Bar]) operation
impl Index<Range<usize>> for AsciiStr[src]
type Output = AsciiStr
The returned type after indexing
fn index(&self, index: Range<usize>) -> &AsciiStr
The method for the indexing (Foo[Bar]) operation
impl IndexMut<Range<usize>> for AsciiStr[src]
fn index_mut(&mut self, index: Range<usize>) -> &mut AsciiStr
The method for the indexing (Foo[Bar]) operation
impl Index<RangeTo<usize>> for AsciiStr[src]
type Output = AsciiStr
The returned type after indexing
fn index(&self, index: RangeTo<usize>) -> &AsciiStr
The method for the indexing (Foo[Bar]) operation
impl IndexMut<RangeTo<usize>> for AsciiStr[src]
fn index_mut(&mut self, index: RangeTo<usize>) -> &mut AsciiStr
The method for the indexing (Foo[Bar]) operation
impl Index<RangeFrom<usize>> for AsciiStr[src]
type Output = AsciiStr
The returned type after indexing
fn index(&self, index: RangeFrom<usize>) -> &AsciiStr
The method for the indexing (Foo[Bar]) operation
impl IndexMut<RangeFrom<usize>> for AsciiStr[src]
fn index_mut(&mut self, index: RangeFrom<usize>) -> &mut AsciiStr
The method for the indexing (Foo[Bar]) operation
impl Index<RangeFull> for AsciiStr[src]
type Output = AsciiStr
The returned type after indexing
fn index(&self, index: RangeFull) -> &AsciiStr
The method for the indexing (Foo[Bar]) operation