Struct ascii::AsciiStr [] [src]

pub struct AsciiStr {
    // some fields omitted
}

AsciiStr represents a byte or string slice that only contains ASCII characters.

It wraps an [AsciiChar] and implements many of strs 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]

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 as_bytes(&self) -> &[u8]

Converts &self into a byte slice.

fn as_slice(&self) -> &[AsciiChar]

Returns the entire string as slice of AsciiChars.

fn as_mut_slice(&mut self) -> &mut [AsciiChar]

Returns the entire string as mutable slice of AsciiChars.

fn as_ptr(&self) -> *const AsciiChar

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.

fn as_mut_ptr(&mut self) -> *mut AsciiChar

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.

fn to_ascii_string(&self) -> AsciiString

Copies the content of this AsciiStr into an owned AsciiString.

fn from_ascii<B: ?Sized>(bytes: &B) -> Result<&AsciiStrAsAsciiStrError> where B: AsRef<[u8]>

Converts anything that can represent a byte slice into an AsciiStr.

Examples

let foo = AsciiStr::from_ascii("foo");
let err = AsciiStr::from_ascii("Ŋ");
assert_eq!(foo.unwrap().as_str(), "foo");
assert_eq!(err.unwrap_err().valid_up_to(), 0);

unsafe fn from_ascii_unchecked<B: ?Sized>(bytes: &B) -> &AsciiStr where B: AsRef<[u8]>

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("foo") };
assert_eq!(foo.as_str(), "foo");

fn len(&self) -> usize

Returns the number of characters / bytes in this ASCII sequence.

Examples

let s = AsciiStr::from_ascii("foo").unwrap();
assert_eq!(s.len(), 3);

fn is_empty(&self) -> bool

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());

fn trim(&self) -> &Self

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());

fn trim_left(&self) -> &Self

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_left());

fn trim_right(&self) -> &Self

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_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: Hasher
1.3.0

Feeds a slice of this type into the state provided.

impl Ord for AsciiStr
[src]

fn cmp(&self, __arg_0: &AsciiStr) -> Ordering

This method returns an Ordering between self and other. Read more

impl PartialOrd for AsciiStr
[src]

fn partial_cmp(&self, __arg_0: &AsciiStr) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more

fn lt(&self, __arg_0: &AsciiStr) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more

fn le(&self, __arg_0: &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, __arg_0: &AsciiStr) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more

fn ge(&self, __arg_0: &AsciiStr) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl Eq for AsciiStr
[src]

impl PartialEq for AsciiStr
[src]

fn eq(&self, __arg_0: &AsciiStr) -> bool

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, __arg_0: &AsciiStr) -> 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) -> bool
1.0.0

This method tests for !=.

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]

fn as_ref(&self) -> &[u8]

Performs the conversion.

impl AsRef<str> for AsciiStr
[src]

fn as_ref(&self) -> &str

Performs the conversion.

impl AsRef<[AsciiChar]> for AsciiStr
[src]

fn as_ref(&self) -> &[AsciiChar]

Performs the conversion.

impl AsMut<[AsciiChar]> for AsciiStr
[src]

fn as_mut(&mut self) -> &mut [AsciiChar]

Performs the conversion.

impl Default for &'static AsciiStr
[src]

fn default() -> &'static AsciiStr

Returns the "default value" for a type. Read more

impl<'a> From<&'a [AsciiChar]> for &'a AsciiStr
[src]

fn from(slice: &[AsciiChar]) -> &AsciiStr

Performs the conversion.

impl<'a> From<&'a mut [AsciiChar]> for &'a mut AsciiStr
[src]

fn from(slice: &mut [AsciiChar]) -> &mut AsciiStr

Performs the conversion.

impl Display for AsciiStr
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Debug for AsciiStr
[src]

fn fmt(&self, f: &mut Formatter) -> Result

Formats the value using the given formatter.

impl Index<usize> for AsciiStr
[src]

type Output = AsciiChar

The returned type after indexing

fn index(&self, index: usize) -> &AsciiChar

The method for the indexing (Foo[Bar]) operation

impl IndexMut<usize> for AsciiStr
[src]

fn index_mut(&mut self, index: usize) -> &mut AsciiChar

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

impl IndexMut<RangeFull> for AsciiStr
[src]

fn index_mut(&mut self, index: RangeFull) -> &mut AsciiStr

The method for the indexing (Foo[Bar]) operation

impl AsciiExt for AsciiStr
[src]

type Owned = AsciiString

Container type for copied ASCII characters.

fn is_ascii(&self) -> bool

Checks if the value is within the ASCII range. Read more

fn to_ascii_uppercase(&self) -> AsciiString

Makes a copy of the string in ASCII upper case. Read more

fn to_ascii_lowercase(&self) -> AsciiString

Makes a copy of the string in ASCII lower case. Read more

fn eq_ignore_ascii_case(&self, other: &Self) -> bool

Checks that two strings are an ASCII case-insensitive match. Read more

fn make_ascii_uppercase(&mut self)

Converts this type to its ASCII upper case equivalent in-place. Read more

fn make_ascii_lowercase(&mut self)

Converts this type to its ASCII lower case equivalent in-place. Read more

impl AsAsciiStr for AsciiStr
[src]

fn as_ascii_str(&self) -> Result<&AsciiStrAsAsciiStrError>

Convert to an ASCII slice.

unsafe fn as_ascii_str_unchecked(&self) -> &AsciiStr

Convert to an ASCII slice without checking for non-ASCII characters.

impl AsMutAsciiStr for AsciiStr
[src]

fn as_mut_ascii_str(&mut self) -> Result<&mut AsciiStrAsAsciiStrError>

Convert to a mutable ASCII slice.

unsafe fn as_mut_ascii_str_unchecked(&mut self) -> &mut AsciiStr

Convert to a mutable ASCII slice without checking for non-ASCII characters.

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 !=.