Struct ascii::AsciiStr[][src]

pub struct AsciiStr { /* 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]

Coerces into an AsciiStr slice.

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.

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

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

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.

Important traits for Lines<'a>

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

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

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'.

Trait Implementations

impl PartialEq for AsciiStr
[src]

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

This method tests for !=.

impl Eq for AsciiStr
[src]

impl PartialOrd for AsciiStr
[src]

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

impl Ord for AsciiStr
[src]

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

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

impl Hash for AsciiStr
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more

impl PartialEq<str> for AsciiStr
[src]

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

This method tests for !=.

impl PartialEq<AsciiStr> for str
[src]

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

This method tests for !=.

impl ToOwned for AsciiStr
[src]

Creates owned data from borrowed data, usually by cloning. Read more

🔬 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 AsRef<[u8]> for AsciiStr
[src]

Performs the conversion.

impl AsRef<str> for AsciiStr
[src]

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

impl Default for &'static AsciiStr
[src]

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

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

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

Performs the conversion.

impl Display for AsciiStr
[src]

Formats the value using the given formatter. Read more

impl Debug for AsciiStr
[src]

Formats the value using the given formatter. Read more

impl Index<Range<usize>> for AsciiStr
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl IndexMut<Range<usize>> for AsciiStr
[src]

Performs the mutable indexing (container[index]) operation.

impl Index<RangeTo<usize>> for AsciiStr
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl IndexMut<RangeTo<usize>> for AsciiStr
[src]

Performs the mutable indexing (container[index]) operation.

impl Index<RangeFrom<usize>> for AsciiStr
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl IndexMut<RangeFrom<usize>> for AsciiStr
[src]

Performs the mutable indexing (container[index]) operation.

impl Index<RangeFull> for AsciiStr
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl IndexMut<RangeFull> for AsciiStr
[src]

Performs the mutable indexing (container[index]) operation.

impl Index<usize> for AsciiStr
[src]

The returned type after indexing.

Performs the indexing (container[index]) operation.

impl IndexMut<usize> for AsciiStr
[src]

Performs the mutable indexing (container[index]) operation.

impl AsciiExt for AsciiStr
[src]

Deprecated since 1.26.0

: use inherent methods instead

Container type for copied ASCII characters.

Deprecated since 1.26.0

: use inherent methods instead

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

Deprecated since 1.26.0

: use inherent methods instead

Makes a copy of the value in its ASCII upper case equivalent. Read more

Deprecated since 1.26.0

: use inherent methods instead

Makes a copy of the value in its ASCII lower case equivalent. Read more

Deprecated since 1.26.0

: use inherent methods instead

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

Deprecated since 1.26.0

: use inherent methods instead

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

Deprecated since 1.26.0

: use inherent methods instead

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

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII alphabetic character: U+0041 'A' ... U+005A 'Z' or U+0061 'a' ... U+007A 'z'. For strings, true if all characters in the string are ASCII alphabetic. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII uppercase character: U+0041 'A' ... U+005A 'Z'. For strings, true if all characters in the string are ASCII uppercase. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII lowercase character: U+0061 'a' ... U+007A 'z'. For strings, true if all characters in the string are ASCII lowercase. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII alphanumeric character: U+0041 'A' ... U+005A 'Z', U+0061 'a' ... U+007A 'z', or U+0030 '0' ... U+0039 '9'. For strings, true if all characters in the string are ASCII alphanumeric. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII decimal digit: U+0030 '0' ... U+0039 '9'. For strings, true if all characters in the string are ASCII digits. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII hexadecimal digit: U+0030 '0' ... U+0039 '9', U+0041 'A' ... U+0046 'F', or U+0061 'a' ... U+0066 'f'. For strings, true if all characters in the string are ASCII hex digits. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII punctuation character: Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII graphic character: U+0021 '!' ... U+007E '~'. For strings, true if all characters in the string are ASCII graphic characters. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII whitespace character: U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED, U+000C FORM FEED, or U+000D CARRIAGE RETURN. For strings, true if all characters in the string are ASCII whitespace. Read more

Deprecated since 1.26.0

: use inherent methods instead

🔬 This is a nightly-only experimental API. (ascii_ctype)

Checks if the value is an ASCII control character: U+0000 NUL ... U+001F UNIT SEPARATOR, or U+007F DELETE. Note that most ASCII whitespace characters are control characters, but SPACE is not. Read more

impl<'a> IntoIterator for &'a AsciiStr
[src]

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

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

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

impl AsAsciiStr for AsciiStr
[src]

Convert to an ASCII slice.

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

impl AsMutAsciiStr for AsciiStr
[src]

Convert to a mutable ASCII slice.

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

impl<'a> PartialEq<String> for &'a AsciiStr
[src]

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

This method tests for !=.

impl<'a> PartialEq<&'a AsciiStr> for String
[src]

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

This method tests for !=.

impl<'a> PartialEq<AsciiString> for &'a AsciiStr
[src]

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

This method tests for !=.

impl<'a> PartialEq<&'a AsciiStr> for AsciiString
[src]

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

This method tests for !=.

impl Borrow<AsciiStr> for AsciiString
[src]

Immutably borrows from an owned value. Read more

impl AsRef<AsciiStr> for AsciiString
[src]

Performs the conversion.

impl AsMut<AsciiStr> for AsciiString
[src]

Performs the conversion.

impl<'a> FromIterator<&'a AsciiStr> for AsciiString
[src]

Creates a value from an iterator. Read more

impl<'a> Extend<&'a AsciiStr> for AsciiString
[src]

Extends a collection with the contents of an iterator. Read more

impl<'a> Add<&'a AsciiStr> for AsciiString
[src]

The resulting type after applying the + operator.

Performs the + operation.

Auto Trait Implementations

impl Send for AsciiStr

impl Sync for AsciiStr