ascii

Enum AsciiChar

Source
#[repr(u8)]
pub enum AsciiChar {
Show 128 variants Null = 0, SOH = 1, SOX = 2, ETX = 3, EOT = 4, ENQ = 5, ACK = 6, Bell = 7, BackSpace = 8, Tab = 9, LineFeed = 10, VT = 11, FF = 12, CarriageReturn = 13, SI = 14, SO = 15, DLE = 16, DC1 = 17, DC2 = 18, DC3 = 19, DC4 = 20, NAK = 21, SYN = 22, ETB = 23, CAN = 24, EM = 25, SUB = 26, ESC = 27, FS = 28, GS = 29, RS = 30, US = 31, Space = 32, Exclamation = 33, Quotation = 34, Hash = 35, Dollar = 36, Percent = 37, Ampersand = 38, Apostrophe = 39, ParenOpen = 40, ParenClose = 41, Asterisk = 42, Plus = 43, Comma = 44, Minus = 45, Dot = 46, Slash = 47, _0 = 48, _1 = 49, _2 = 50, _3 = 51, _4 = 52, _5 = 53, _6 = 54, _7 = 55, _8 = 56, _9 = 57, Colon = 58, Semicolon = 59, LessThan = 60, Equal = 61, GreaterThan = 62, Question = 63, At = 64, A = 65, B = 66, C = 67, D = 68, E = 69, F = 70, G = 71, H = 72, I = 73, J = 74, K = 75, L = 76, M = 77, N = 78, O = 79, P = 80, Q = 81, R = 82, S = 83, T = 84, U = 85, V = 86, W = 87, X = 88, Y = 89, Z = 90, BracketOpen = 91, BackSlash = 92, BracketClose = 93, Caret = 94, UnderScore = 95, Grave = 96, a = 97, b = 98, c = 99, d = 100, e = 101, f = 102, g = 103, h = 104, i = 105, j = 106, k = 107, l = 108, m = 109, n = 110, o = 111, p = 112, q = 113, r = 114, s = 115, t = 116, u = 117, v = 118, w = 119, x = 120, y = 121, z = 122, CurlyBraceOpen = 123, VerticalBar = 124, CurlyBraceClose = 125, Tilde = 126, DEL = 127,
}
Expand description

An ASCII character. It wraps a u8, with the highest bit always zero.

Variants§

§

Null = 0

'\0'

§

SOH = 1

§

SOX = 2

§

ETX = 3

§

EOT = 4

§

ENQ = 5

§

ACK = 6

§

Bell = 7

bell / alarm / audible

'\a' is not recognized by Rust.

§

BackSpace = 8

Backspace

'\b' is not recognized by Rust.

§

Tab = 9

'\t'

§

LineFeed = 10

'\n'

§

VT = 11

Vertical tab

'\v' is not recognized by Rust.

§

FF = 12

Form Feed

'\f' is not recognized by Rust.

§

CarriageReturn = 13

'\r'

§

SI = 14

§

SO = 15

§

DLE = 16

§

DC1 = 17

§

DC2 = 18

Device control 2

§

DC3 = 19

Device control 3, Often XOFF

§

DC4 = 20

Device control 4

§

NAK = 21

§

SYN = 22

§

ETB = 23

§

CAN = 24

§

EM = 25

§

SUB = 26

§

ESC = 27

Escape

'\e' is not recognized by Rust.

§

FS = 28

§

GS = 29

§

RS = 30

§

US = 31

§

Space = 32

' '

§

Exclamation = 33

'!'

§

Quotation = 34

'"'

§

Hash = 35

'#'

§

Dollar = 36

'$'

§

Percent = 37

'%'

§

Ampersand = 38

'&'

§

Apostrophe = 39

'\''

§

ParenOpen = 40

'('

§

ParenClose = 41

')'

§

Asterisk = 42

'*'

§

Plus = 43

'+'

§

Comma = 44

','

§

Minus = 45

'-'

§

Dot = 46

'.'

§

Slash = 47

'/'

§

_0 = 48

'0'

§

_1 = 49

'1'

§

_2 = 50

'2'

§

_3 = 51

'3'

§

_4 = 52

'4'

§

_5 = 53

'5'

§

_6 = 54

'6'

§

_7 = 55

'7'

§

_8 = 56

'8'

§

_9 = 57

'9'

§

Colon = 58

':'

§

Semicolon = 59

';'

§

LessThan = 60

'<'

§

Equal = 61

'='

§

GreaterThan = 62

'>'

§

Question = 63

'?'

§

At = 64

'@'

§

A = 65

'A'

§

B = 66

'B'

§

C = 67

'C'

§

D = 68

'D'

§

E = 69

'E'

§

F = 70

'F'

§

G = 71

'G'

§

H = 72

'H'

§

I = 73

'I'

§

J = 74

'J'

§

K = 75

'K'

§

L = 76

'L'

§

M = 77

'M'

§

N = 78

'N'

§

O = 79

'O'

§

P = 80

'P'

§

Q = 81

'Q'

§

R = 82

'R'

§

S = 83

'S'

§

T = 84

'T'

§

U = 85

'U'

§

V = 86

'V'

§

W = 87

'W'

§

X = 88

'X'

§

Y = 89

'Y'

§

Z = 90

'Z'

§

BracketOpen = 91

'['

§

BackSlash = 92

'\'

§

BracketClose = 93

']'

§

Caret = 94

'_'

§

UnderScore = 95

'_'

§

Grave = 96

'’`

§

a = 97

'a'

§

b = 98

'b'

§

c = 99

'c'

§

d = 100

'd'

§

e = 101

'e'

§

f = 102

'f'

§

g = 103

'g'

§

h = 104

'h'

§

i = 105

'i'

§

j = 106

'j'

§

k = 107

'k'

§

l = 108

'l'

§

m = 109

'm'

§

n = 110

'n'

§

o = 111

'o'

§

p = 112

'p'

§

q = 113

'q'

§

r = 114

'r'

§

s = 115

's'

§

t = 116

't'

§

u = 117

'u'

§

v = 118

'v'

§

w = 119

'w'

§

x = 120

'x'

§

y = 121

'y'

§

z = 122

'z'

§

CurlyBraceOpen = 123

'{'

§

VerticalBar = 124

'|'

§

CurlyBraceClose = 125

'}'

§

Tilde = 126

'~'

§

DEL = 127

Implementations§

Source§

impl AsciiChar

Source

pub fn from<C: ToAsciiChar>(ch: C) -> Result<Self, ToAsciiCharError>

Constructs an ASCII character from a u8, char or other character type.

§Failure

Returns Err(()) if the character can’t be ASCII encoded.

§Example
let a = AsciiChar::from('g').unwrap();
assert_eq!(a.as_char(), 'g');
Source

pub unsafe fn from_unchecked<C: ToAsciiChar>(ch: C) -> Self

Constructs an ASCII character from a char or u8 without any checks.

Source

pub fn as_byte(self) -> u8

Converts an ASCII character into a u8.

Source

pub fn as_char(self) -> char

Converts an ASCII character into a char.

Source

pub fn is_alphabetic(self) -> bool

Check if the character is a letter (a-z, A-Z)

Source

pub fn is_digit(self) -> bool

Check if the character is a number (0-9)

Source

pub fn is_alphanumeric(self) -> bool

Check if the character is a letter or number

Source

pub fn is_blank(self) -> bool

Check if the character is a space or horizontal tab

Source

pub fn is_whitespace(self) -> bool

Check if the character is a ’ ’, ‘\t’, ‘\n’ or ‘\r’

Source

pub fn is_control(self) -> bool

Check if the character is a control character

§Examples
use ascii::ToAsciiChar;
assert_eq!('\0'.to_ascii_char().unwrap().is_control(), true);
assert_eq!('n'.to_ascii_char().unwrap().is_control(), false);
assert_eq!(' '.to_ascii_char().unwrap().is_control(), false);
assert_eq!('\n'.to_ascii_char().unwrap().is_control(), true);
Source

pub fn is_graph(self) -> bool

Checks if the character is printable (except space)

§Examples
use ascii::ToAsciiChar;
assert_eq!('n'.to_ascii_char().unwrap().is_graph(), true);
assert_eq!(' '.to_ascii_char().unwrap().is_graph(), false);
assert_eq!('\n'.to_ascii_char().unwrap().is_graph(), false);
Source

pub fn is_print(self) -> bool

Checks if the character is printable (including space)

§Examples
use ascii::ToAsciiChar;
assert_eq!('n'.to_ascii_char().unwrap().is_print(), true);
assert_eq!(' '.to_ascii_char().unwrap().is_print(), true);
assert_eq!('\n'.to_ascii_char().unwrap().is_print(), false);
Source

pub fn is_lowercase(self) -> bool

Checks if the character is alphabetic and lowercase

§Examples
use ascii::ToAsciiChar;
assert_eq!('a'.to_ascii_char().unwrap().is_lowercase(), true);
assert_eq!('A'.to_ascii_char().unwrap().is_lowercase(), false);
assert_eq!('@'.to_ascii_char().unwrap().is_lowercase(), false);
Source

pub fn is_uppercase(self) -> bool

Checks if the character is alphabetic and uppercase

§Examples
use ascii::ToAsciiChar;
assert_eq!('A'.to_ascii_char().unwrap().is_uppercase(), true);
assert_eq!('a'.to_ascii_char().unwrap().is_uppercase(), false);
assert_eq!('@'.to_ascii_char().unwrap().is_uppercase(), false);
Source

pub fn is_punctuation(self) -> bool

Checks if the character is punctuation

§Examples
use ascii::ToAsciiChar;
assert_eq!('n'.to_ascii_char().unwrap().is_punctuation(), false);
assert_eq!(' '.to_ascii_char().unwrap().is_punctuation(), false);
assert_eq!('_'.to_ascii_char().unwrap().is_punctuation(), true);
assert_eq!('~'.to_ascii_char().unwrap().is_punctuation(), true);
Source

pub fn is_hex(self) -> bool

Checks if the character is a valid hex digit

§Examples
use ascii::ToAsciiChar;
assert_eq!('5'.to_ascii_char().unwrap().is_hex(), true);
assert_eq!('a'.to_ascii_char().unwrap().is_hex(), true);
assert_eq!('F'.to_ascii_char().unwrap().is_hex(), true);
assert_eq!('G'.to_ascii_char().unwrap().is_hex(), false);
assert_eq!(' '.to_ascii_char().unwrap().is_hex(), false);
Source

pub fn as_printable_char(self) -> char

Unicode has printable versions of the ASCII control codes, like ‘␛’.

This function is identical with .as_char() for all values .is_printable() returns true for, but replaces the control codes with those unicodes printable versions.

§Examples
assert_eq!('\0'.to_ascii_char().unwrap().as_printable_char(), '␀');
assert_eq!('\n'.to_ascii_char().unwrap().as_printable_char(), '␊');
assert_eq!(' '.to_ascii_char().unwrap().as_printable_char(), ' ');
assert_eq!('p'.to_ascii_char().unwrap().as_printable_char(), 'p');
Source

pub fn make_ascii_uppercase(&mut self)

Replaces letters a to z with A to Z

Source

pub fn make_ascii_lowercase(&mut self)

Replaces letters A to Z with a to z

Source

pub fn to_ascii_uppercase(&self) -> Self

Maps letters az to AZ and returns everything else unchanged.

Source

pub fn to_ascii_lowercase(&self) -> Self

Maps letters AZ to az and returns everything else unchanged.

Source

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

Compares two characters case-insensitively.

Trait Implementations§

Source§

impl AsciiExt for AsciiChar

Source§

type Owned = AsciiChar

👎Deprecated since 1.26.0: use inherent methods instead
Container type for copied ASCII characters.
Source§

fn is_ascii(&self) -> bool

👎Deprecated since 1.26.0: use inherent methods instead
Checks if the value is within the ASCII range. Read more
Source§

fn to_ascii_uppercase(&self) -> AsciiChar

👎Deprecated since 1.26.0: use inherent methods instead
Makes a copy of the value in its ASCII upper case equivalent. Read more
Source§

fn to_ascii_lowercase(&self) -> AsciiChar

👎Deprecated since 1.26.0: use inherent methods instead
Makes a copy of the value in its ASCII lower case equivalent. Read more
Source§

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

👎Deprecated since 1.26.0: use inherent methods instead
Checks that two values are an ASCII case-insensitive match. Read more
Source§

fn make_ascii_uppercase(&mut self)

👎Deprecated since 1.26.0: use inherent methods instead
Converts this type to its ASCII upper case equivalent in-place. Read more
Source§

fn make_ascii_lowercase(&mut self)

👎Deprecated since 1.26.0: use inherent methods instead
Converts this type to its ASCII lower case equivalent in-place. Read more
Source§

impl Clone for AsciiChar

Source§

fn clone(&self) -> AsciiChar

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AsciiChar

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for AsciiChar

Source§

fn default() -> AsciiChar

Returns the “default value” for a type. Read more
Source§

impl Display for AsciiChar

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Extend<&'a AsciiChar> for AsciiString

Source§

fn extend<I: IntoIterator<Item = &'a AsciiChar>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl Extend<AsciiChar> for AsciiString

Source§

fn extend<I: IntoIterator<Item = AsciiChar>>(&mut self, iterable: I)

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<AsciiChar> for char

Source§

fn from(a: AsciiChar) -> char

Converts to this type from the input type.
Source§

impl From<AsciiChar> for u8

Source§

fn from(a: AsciiChar) -> u8

Converts to this type from the input type.
Source§

impl FromIterator<AsciiChar> for AsciiString

Source§

fn from_iter<I: IntoIterator<Item = AsciiChar>>(iter: I) -> AsciiString

Creates a value from an iterator. Read more
Source§

impl Hash for AsciiChar

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for AsciiChar

Source§

fn cmp(&self, other: &AsciiChar) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq<AsciiChar> for char

Source§

fn eq(&self, rhs: &AsciiChar) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<AsciiChar> for u8

Source§

fn eq(&self, rhs: &AsciiChar) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<char> for AsciiChar

Source§

fn eq(&self, rhs: &char) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq<u8> for AsciiChar

Source§

fn eq(&self, rhs: &u8) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialEq for AsciiChar

Source§

fn eq(&self, other: &AsciiChar) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd<AsciiChar> for char

Source§

fn partial_cmp(&self, rhs: &AsciiChar) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<AsciiChar> for u8

Source§

fn partial_cmp(&self, rhs: &AsciiChar) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<char> for AsciiChar

Source§

fn partial_cmp(&self, rhs: &char) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd<u8> for AsciiChar

Source§

fn partial_cmp(&self, rhs: &u8) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl PartialOrd for AsciiChar

Source§

fn partial_cmp(&self, other: &AsciiChar) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl ToAsciiChar for AsciiChar

Source§

fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError>

Convert to AsciiChar.
Source§

unsafe fn to_ascii_char_unchecked(self) -> AsciiChar

Convert to AsciiChar without checking that it is an ASCII character.
Source§

impl Copy for AsciiChar

Source§

impl Eq for AsciiChar

Source§

impl StructuralPartialEq for AsciiChar

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.