[−][src]Struct ascii::AsciiStr
AsciiStr represents a byte or string slice that only contains ASCII characters.
It wraps an [AsciiChar]
and implements many of str
s methods and traits.
It can be created by a checked conversion from a str
or [u8]
, or borrowed from an
AsciiString
.
Methods
impl AsciiStr
[src]
pub fn as_str(&self) -> &str
[src]
Converts &self
to a &str
slice.
pub fn as_bytes(&self) -> &[u8]
[src]
Converts &self
into a byte slice.
pub const fn as_slice(&self) -> &[AsciiChar]
[src]
Returns the entire string as slice of AsciiChar
s.
pub fn as_mut_slice(&mut self) -> &mut [AsciiChar]
[src]
Returns the entire string as mutable slice of AsciiChar
s.
pub const fn as_ptr(&self) -> *const AsciiChar
[src]
Returns a raw pointer to the AsciiStr
's buffer.
The caller must ensure that the slice outlives the pointer this function returns, or else it
will end up pointing to garbage. Modifying the AsciiStr
may cause it's buffer to be
reallocated, which would also make any pointers to it invalid.
pub fn as_mut_ptr(&mut self) -> *mut AsciiChar
[src]
Returns an unsafe mutable pointer to the AsciiStr
's buffer.
The caller must ensure that the slice outlives the pointer this function returns, or else it
will end up pointing to garbage. Modifying the AsciiStr
may cause it's buffer to be
reallocated, which would also make any pointers to it invalid.
pub fn to_ascii_string(&self) -> AsciiString
[src]
Copies the content of this AsciiStr
into an owned AsciiString
.
pub fn from_ascii<B: ?Sized>(bytes: &B) -> Result<&AsciiStr, AsAsciiStrError> where
B: AsRef<[u8]>,
[src]
B: AsRef<[u8]>,
Converts anything that can represent a byte slice into an AsciiStr
.
Examples
let foo = AsciiStr::from_ascii(b"foo"); let err = AsciiStr::from_ascii("Ŋ"); assert_eq!(foo.unwrap().as_str(), "foo"); assert_eq!(err.unwrap_err().valid_up_to(), 0);
pub unsafe fn from_ascii_unchecked(bytes: &[u8]) -> &AsciiStr
[src]
Converts anything that can be represented as a byte slice to an AsciiStr
without checking
for non-ASCII characters..
Examples
let foo = unsafe { AsciiStr::from_ascii_unchecked(&b"foo"[..]) }; assert_eq!(foo.as_str(), "foo");
pub fn len(&self) -> usize
[src]
Returns the number of characters / bytes in this ASCII sequence.
Examples
let s = AsciiStr::from_ascii("foo").unwrap(); assert_eq!(s.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Returns true if the ASCII slice contains zero bytes.
Examples
let mut empty = AsciiStr::from_ascii("").unwrap(); let mut full = AsciiStr::from_ascii("foo").unwrap(); assert!(empty.is_empty()); assert!(!full.is_empty());
ⓘImportant traits for Chars<'a>pub fn chars(&self) -> Chars
[src]
Returns an iterator over the characters of the AsciiStr
.
ⓘImportant traits for CharsMut<'a>pub fn chars_mut(&mut self) -> CharsMut
[src]
Returns an iterator over the characters of the AsciiStr
which allows you to modify the
value of each AsciiChar
.
pub fn split(&self, on: AsciiChar) -> impl DoubleEndedIterator<Item = &AsciiStr>
[src]
Returns an iterator over parts of the AsciiStr
separated by a character.
Examples
let words = AsciiStr::from_ascii("apple banana lemon").unwrap() .split(AsciiChar::Space) .map(|a| a.as_str()) .collect::<Vec<_>>(); assert_eq!(words, ["apple", "banana", "lemon"]);
pub fn lines(&self) -> impl DoubleEndedIterator<Item = &AsciiStr>
[src]
Returns an iterator over the lines of the AsciiStr
, which are themselves AsciiStr
s.
Lines are ended with either LineFeed
(\n
), or CarriageReturn
then LineFeed
(\r\n
).
The final line ending is optional.
pub fn trim(&self) -> &Self
[src]
Returns an ASCII string slice with leading and trailing whitespace removed.
Examples
let example = AsciiStr::from_ascii(" \twhite \tspace \t").unwrap(); assert_eq!("white \tspace", example.trim());
pub fn trim_start(&self) -> &Self
[src]
Returns an ASCII string slice with leading whitespace removed.
Examples
let example = AsciiStr::from_ascii(" \twhite \tspace \t").unwrap(); assert_eq!("white \tspace \t", example.trim_start());
pub fn trim_end(&self) -> &Self
[src]
Returns an ASCII string slice with trailing whitespace removed.
Examples
let example = AsciiStr::from_ascii(" \twhite \tspace \t").unwrap(); assert_eq!(" \twhite \tspace", example.trim_end());
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
[src]
Compares two strings case-insensitively.
pub fn make_ascii_uppercase(&mut self)
[src]
Replaces lowercase letters with their uppercase equivalent.
pub fn make_ascii_lowercase(&mut self)
[src]
Replaces uppercase letters with their lowercase equivalent.
pub fn to_ascii_uppercase(&self) -> AsciiString
[src]
Returns a copy of this string where letters 'a' to 'z' are mapped to 'A' to 'Z'.
pub fn to_ascii_lowercase(&self) -> AsciiString
[src]
Returns a copy of this string where letters 'A' to 'Z' are mapped to 'a' to 'z'.
pub fn first(&self) -> Option<AsciiChar>
[src]
Returns the first character if the string is not empty.
pub fn last(&self) -> Option<AsciiChar>
[src]
Returns the last character if the string is not empty.
Trait Implementations
impl AsAsciiStr for AsciiStr
[src]
type Inner = AsciiChar
fn slice_ascii<R>(&self, range: R) -> Result<&AsciiStr, AsAsciiStrError> where
R: SliceIndex<[AsciiChar], Output = [AsciiChar]>,
[src]
R: SliceIndex<[AsciiChar], Output = [AsciiChar]>,
fn as_ascii_str(&self) -> Result<&AsciiStr, AsAsciiStrError>
[src]
unsafe fn as_ascii_str_unchecked(&self) -> &AsciiStr
[src]
fn get_ascii(&self, index: usize) -> Option<AsciiChar>
[src]
impl AsMutAsciiStr for AsciiStr
[src]
fn slice_ascii_mut<R>(
&mut self,
range: R
) -> Result<&mut AsciiStr, AsAsciiStrError> where
R: SliceIndex<[AsciiChar], Output = [AsciiChar]>,
[src]
&mut self,
range: R
) -> Result<&mut AsciiStr, AsAsciiStrError> where
R: SliceIndex<[AsciiChar], Output = [AsciiChar]>,
unsafe fn as_mut_ascii_str_unchecked(&mut self) -> &mut AsciiStr
[src]
fn as_mut_ascii_str(&mut self) -> Result<&mut AsciiStr, AsAsciiStrError>
[src]
Convert to a mutable ASCII slice.
impl<'a> IntoAsciiString for &'a AsciiStr
[src]
unsafe fn into_ascii_string_unchecked(self) -> AsciiString
[src]
fn into_ascii_string(self) -> Result<AsciiString, FromAsciiError<Self>>
[src]
impl AsRef<[u8]> for AsciiStr
[src]
impl AsRef<str> for AsciiStr
[src]
impl AsRef<[AsciiChar]> for AsciiStr
[src]
impl AsRef<AsciiStr> for AsciiStr
[src]
impl AsRef<AsciiStr> for [AsciiChar]
[src]
impl AsRef<AsciiStr> for AsciiChar
[src]
impl AsRef<AsciiStr> for AsciiString
[src]
impl<'a> IntoIterator for &'a AsciiStr
[src]
Produces references for compatibility with [u8]
.
(str
doesn't implement IntoIterator
for its references,
so there is no compatibility to lose.)
type Item = &'a AsciiChar
The type of the elements being iterated over.
type IntoIter = CharsRef<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a> IntoIterator for &'a mut AsciiStr
[src]
type Item = &'a mut AsciiChar
The type of the elements being iterated over.
type IntoIter = CharsMut<'a>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl Default for &'static AsciiStr
[src]
impl ToOwned for AsciiStr
[src]
type Owned = AsciiString
The resulting type after obtaining ownership.
fn to_owned(&self) -> AsciiString
[src]
fn clone_into(&self, target: &mut Self::Owned)
[src]
🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl Eq for AsciiStr
[src]
impl PartialOrd<AsciiStr> for AsciiStr
[src]
fn partial_cmp(&self, other: &AsciiStr) -> Option<Ordering>
[src]
fn lt(&self, other: &AsciiStr) -> bool
[src]
fn le(&self, other: &AsciiStr) -> bool
[src]
fn gt(&self, other: &AsciiStr) -> bool
[src]
fn ge(&self, other: &AsciiStr) -> bool
[src]
impl PartialEq<AsciiStr> for AsciiStr
[src]
impl PartialEq<str> for AsciiStr
[src]
fn eq(&self, other: &str) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<AsciiStr> for str
[src]
fn eq(&self, other: &AsciiStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<[u8]> for AsciiStr
[src]
fn eq(&self, other: &[u8]) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<AsciiStr> for [u8]
[src]
fn eq(&self, other: &AsciiStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<[AsciiChar]> for AsciiStr
[src]
fn eq(&self, other: &[AsciiChar]) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl PartialEq<AsciiStr> for [AsciiChar]
[src]
fn eq(&self, other: &AsciiStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<String> for &'a AsciiStr
[src]
fn eq(&self, other: &String) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<&'a AsciiStr> for String
[src]
fn eq(&self, other: &&'a AsciiStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<AsciiString> for &'a AsciiStr
[src]
fn eq(&self, other: &AsciiString) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> PartialEq<&'a AsciiStr> for AsciiString
[src]
fn eq(&self, other: &&'a AsciiStr) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
This method tests for !=
.
impl<'a> From<&'a [AsciiChar]> for &'a AsciiStr
[src]
impl<'a> From<&'a mut [AsciiChar]> for &'a mut AsciiStr
[src]
impl<'a> From<&'a AsciiStr> for &'a [AsciiChar]
[src]
impl<'a> From<&'a mut AsciiStr> for &'a mut [AsciiChar]
[src]
impl<'a> From<&'a AsciiStr> for &'a [u8]
[src]
impl<'a> From<&'a AsciiStr> for &'a str
[src]
impl<'a> From<&'a AsciiStr> for AsciiString
[src]
impl<'a> From<&'a AsciiStr> for Cow<'a, AsciiStr>
[src]
impl Ord for AsciiStr
[src]
fn cmp(&self, other: &AsciiStr) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
Compares and returns the minimum of two values. Read more
fn clamp(self, min: Self, max: Self) -> Self
[src]
clamp
)Restrict a value to a certain interval. Read more
impl AsMut<[AsciiChar]> for AsciiStr
[src]
impl AsMut<AsciiStr> for AsciiStr
[src]
impl AsMut<AsciiStr> for [AsciiChar]
[src]
impl AsMut<AsciiStr> for AsciiString
[src]
impl Hash for AsciiStr
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl Display for AsciiStr
[src]
impl Debug for AsciiStr
[src]
impl<'a> Add<&'a AsciiStr> for AsciiString
[src]
type Output = AsciiString
The resulting type after applying the +
operator.
fn add(self, other: &AsciiStr) -> AsciiString
[src]
impl<'a> AddAssign<&'a AsciiStr> for AsciiString
[src]
fn add_assign(&mut self, other: &AsciiStr)
[src]
impl Index<Range<usize>> for AsciiStr
[src]
type Output = AsciiStr
The returned type after indexing.
fn index(&self, index: Range<usize>) -> &AsciiStr
[src]
impl Index<RangeTo<usize>> for AsciiStr
[src]
type Output = AsciiStr
The returned type after indexing.
fn index(&self, index: RangeTo<usize>) -> &AsciiStr
[src]
impl Index<RangeFrom<usize>> for AsciiStr
[src]
type Output = AsciiStr
The returned type after indexing.
fn index(&self, index: RangeFrom<usize>) -> &AsciiStr
[src]
impl Index<RangeFull> for AsciiStr
[src]
type Output = AsciiStr
The returned type after indexing.
fn index(&self, index: RangeFull) -> &AsciiStr
[src]
impl Index<RangeInclusive<usize>> for AsciiStr
[src]
type Output = AsciiStr
The returned type after indexing.
fn index(&self, index: RangeInclusive<usize>) -> &AsciiStr
[src]
impl Index<RangeToInclusive<usize>> for AsciiStr
[src]
type Output = AsciiStr
The returned type after indexing.
fn index(&self, index: RangeToInclusive<usize>) -> &AsciiStr
[src]
impl Index<usize> for AsciiStr
[src]
type Output = AsciiChar
The returned type after indexing.
fn index(&self, index: usize) -> &AsciiChar
[src]
impl IndexMut<Range<usize>> for AsciiStr
[src]
impl IndexMut<RangeTo<usize>> for AsciiStr
[src]
impl IndexMut<RangeFrom<usize>> for AsciiStr
[src]
impl IndexMut<RangeFull> for AsciiStr
[src]
impl IndexMut<RangeInclusive<usize>> for AsciiStr
[src]
fn index_mut(&mut self, index: RangeInclusive<usize>) -> &mut AsciiStr
[src]
impl IndexMut<RangeToInclusive<usize>> for AsciiStr
[src]
fn index_mut(&mut self, index: RangeToInclusive<usize>) -> &mut AsciiStr
[src]
impl IndexMut<usize> for AsciiStr
[src]
impl Borrow<AsciiStr> for AsciiString
[src]
impl BorrowMut<AsciiStr> for AsciiString
[src]
fn borrow_mut(&mut self) -> &mut AsciiStr
[src]
Auto Trait Implementations
impl Unpin for AsciiStr
impl Sync for AsciiStr
impl Send for AsciiStr
impl UnwindSafe for AsciiStr
impl RefUnwindSafe for AsciiStr
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T> ToString for T where
T: Display + ?Sized,
[src]
T: Display + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,