[−][src]Trait ascii::AsAsciiStr
Convert slices of bytes or AsciiChar to AsciiStr
.
Required methods
fn slice_ascii<R>(&self, range: R) -> Result<&AsciiStr, AsAsciiStrError> where
R: SliceIndex<[Self::Inner], Output = [Self::Inner]>,
R: SliceIndex<[Self::Inner], Output = [Self::Inner]>,
Convert a subslice to an ASCII slice.
Returns Err
if the range is out of bounds or if not all bytes in the
slice are ASCII. The value in the error will be the index of the first
non-ASCII byte or the end of the slice.
Examples
use ascii::AsAsciiStr; assert!("'zoä'".slice_ascii(..3).is_ok()); assert!("'zoä'".slice_ascii(0..4).is_err()); assert!("'zoä'".slice_ascii(5..=5).is_ok()); assert!("'zoä'".slice_ascii(4..).is_err()); assert!(b"\r\n".slice_ascii(..).is_ok());
unsafe fn as_ascii_str_unchecked(&self) -> &AsciiStr
Convert to an ASCII slice without checking for non-ASCII characters.
Examples
Provided methods
fn as_ascii_str(&self) -> Result<&AsciiStr, AsAsciiStrError>
Convert to an ASCII slice.
Example
use ascii::{AsAsciiStr, AsciiChar}; assert!("ASCII".as_ascii_str().is_ok()); assert!(b"\r\n".as_ascii_str().is_ok()); assert!("'zoä'".as_ascii_str().is_err()); assert!(b"\xff".as_ascii_str().is_err()); assert!([AsciiChar::C][..].as_ascii_str().is_ok()); // infallible
fn get_ascii(&self, index: usize) -> Option<AsciiChar>
Get a single ASCII character from the slice.
Returns None
if the index is out of bounds or the byte is not ASCII.
Examples
use ascii::{AsAsciiStr, AsciiChar}; assert_eq!("'zoä'".get_ascii(4), None); assert_eq!("'zoä'".get_ascii(5), Some(AsciiChar::Apostrophe)); assert_eq!("'zoä'".get_ascii(6), None);
Implementors
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 AsAsciiStr for [AsciiChar]
[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 AsAsciiStr for [u8]
[src]
type Inner = u8
fn slice_ascii<R>(&self, range: R) -> Result<&AsciiStr, AsAsciiStrError> where
R: SliceIndex<[u8], Output = [u8]>,
[src]
R: SliceIndex<[u8], Output = [u8]>,
fn as_ascii_str(&self) -> Result<&AsciiStr, AsAsciiStrError>
[src]
unsafe fn as_ascii_str_unchecked(&self) -> &AsciiStr
[src]
impl AsAsciiStr for str
[src]
type Inner = u8
fn slice_ascii<R>(&self, range: R) -> Result<&AsciiStr, AsAsciiStrError> where
R: SliceIndex<[u8], Output = [u8]>,
[src]
R: SliceIndex<[u8], Output = [u8]>,
fn as_ascii_str(&self) -> Result<&AsciiStr, AsAsciiStrError>
[src]
unsafe fn as_ascii_str_unchecked(&self) -> &AsciiStr
[src]
impl<'a, T: ?Sized> AsAsciiStr for &'a T where
T: AsAsciiStr,
[src]
T: AsAsciiStr,
type Inner = <T as AsAsciiStr>::Inner
fn slice_ascii<R>(&self, range: R) -> Result<&AsciiStr, AsAsciiStrError> where
R: SliceIndex<[Self::Inner], Output = [Self::Inner]>,
[src]
R: SliceIndex<[Self::Inner], Output = [Self::Inner]>,
unsafe fn as_ascii_str_unchecked(&self) -> &AsciiStr
[src]
impl<'a, T: ?Sized> AsAsciiStr for &'a mut T where
T: AsAsciiStr,
[src]
T: AsAsciiStr,
type Inner = <T as AsAsciiStr>::Inner
fn slice_ascii<R>(&self, range: R) -> Result<&AsciiStr, AsAsciiStrError> where
R: SliceIndex<[Self::Inner], Output = [Self::Inner]>,
[src]
R: SliceIndex<[Self::Inner], Output = [Self::Inner]>,