#[repr(transparent)]
pub struct AsciiStr { /* private fields */ }
Expand description

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.

Implementations

Converts &self to a &str slice.

Converts &self into a byte slice.

Returns the entire string as slice of AsciiChars.

Returns the entire string as mutable slice of AsciiChars.

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.

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.

Copies the content of this AsciiStr into an owned AsciiString.

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

Errors

If bytes contains a non-ascii byte, Err will be returned

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

Converts anything that can be represented as a byte slice to an AsciiStr without checking for non-ASCII characters..

Safety

If any of the bytes in bytes do not represent valid ascii characters, calling this function is undefined behavior.

Examples
let foo = unsafe { AsciiStr::from_ascii_unchecked(&b"foo"[..]) };
assert_eq!(foo.as_str(), "foo");

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

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

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

Returns an iterator over the characters of the AsciiStr.

Returns an iterator over the characters of the AsciiStr which allows you to modify the value of each AsciiChar.

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"]);

Returns an iterator over the lines of the AsciiStr, which are themselves AsciiStrs.

Lines are ended with either LineFeed (\n), or CarriageReturn then LineFeed (\r\n).

The final line ending is optional.

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

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

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

Compares two strings case-insensitively.

Replaces lowercase letters with their uppercase equivalent.

Replaces uppercase letters with their lowercase equivalent.

Returns a copy of this string where letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’.

Returns a copy of this string where letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’.

Returns the first character if the string is not empty.

Returns the last character if the string is not empty.

Converts a Box<AsciiStr> into a AsciiString without copying or allocating.

Trait Implementations

The resulting type after applying the + operator.
Performs the + operation. Read more
Performs the += operation. Read more
Convert a subslice to an ASCII slice. Read more
Convert to an ASCII slice. Read more
Convert to an ASCII slice without checking for non-ASCII characters. Read more
Get a single ASCII character from the slice. Read more
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Converts this type into a mutable reference of the (usually inferred) input type.
Convert a subslice to an ASCII slice. Read more
Convert to a mutable ASCII slice without checking for non-ASCII characters. Read more
Convert to a mutable ASCII slice. Read more
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Converts this type into a shared reference of the (usually inferred) input type.
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
Feeds this value into the given Hasher. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more
Convert to AsciiString without checking for non-ASCII characters. Read more
Convert to AsciiString. Read more

Produces references for compatibility with [u8].

(str doesn’t implement IntoIterator for its references, so there is no compatibility to lose.)

The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
The type of the elements being iterated over.
Which kind of iterator are we turning this into?
Creates an iterator from a value. Read more
This method returns an Ordering between self and other. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts the given value to a String. Read more