#[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
'\a'
is not recognized by Rust.
BackSpace = 8
'\b'
is not recognized by Rust.
Tab = 9
'\t'
LineFeed = 10
'\n'
VT = 11
'\v'
is not recognized by Rust.
FF = 12
'\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
'\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
impl AsciiChar
Sourcepub fn from_ascii<C: ToAsciiChar>(ch: C) -> Result<Self, ToAsciiCharError>
pub fn from_ascii<C: ToAsciiChar>(ch: C) -> Result<Self, ToAsciiCharError>
Sourcepub const fn new(ch: char) -> AsciiChar
pub const fn new(ch: char) -> AsciiChar
Create an AsciiChar
from a char
, panicking if it’s not ASCII.
This function is intended for creating AsciiChar
values from
hardcoded known-good character literals such as 'K'
, '-'
or '\0'
,
and for use in const
contexts.
Use from_ascii()
instead when you’re not
certain the character is ASCII.
§Examples
assert_eq!(AsciiChar::new('@'), AsciiChar::At);
assert_eq!(AsciiChar::new('C').as_char(), 'C');
In a constant:
const SPLIT_ON: AsciiChar = AsciiChar::new(',');
This will not compile:
const BAD: AsciiChar = AsciiChar::new('Ø');
§Panics
This function will panic if passed a non-ASCII character.
The panic message might not be the most descriptive due to the
current limitations of const fn
.
Sourcepub unsafe fn from_ascii_unchecked(ch: u8) -> Self
pub unsafe fn from_ascii_unchecked(ch: u8) -> Self
Constructs an ASCII character from a u8
, char
or other character
type without any checks.
§Safety
This function is very unsafe as it can create invalid enum
discriminants, which instantly creates undefined behavior.
(let _ = AsciiChar::from_ascii_unchecked(200);
alone is UB).
The undefined behavior is not just theoretical either:
For example, [0; 128][AsciiChar::from_ascii_unchecked(255) as u8 as usize] = 0
might not panic, creating a buffer overflow,
and Some(AsciiChar::from_ascii_unchecked(128))
might be None
.
Sourcepub const fn is_alphabetic(self) -> bool
pub const fn is_alphabetic(self) -> bool
Check if the character is a letter (a-z, A-Z)
Sourcepub const fn is_ascii_alphabetic(&self) -> bool
pub const fn is_ascii_alphabetic(&self) -> bool
Check if the character is a letter (a-z, A-Z).
This method is identical to is_alphabetic()
Sourcepub fn is_digit(self, radix: u32) -> bool
pub fn is_digit(self, radix: u32) -> bool
Check if the character is a digit in the given radix.
If the radix is always 10 or 16,
is_ascii_digit()
and
is_ascii_hexdigit()
will be faster.
§Panics
Radixes greater than 36 are not supported and will result in a panic.
Sourcepub const fn is_ascii_digit(&self) -> bool
pub const fn is_ascii_digit(&self) -> bool
Check if the character is a number (0-9)
§Examples
assert_eq!(AsciiChar::new('0').is_ascii_digit(), true);
assert_eq!(AsciiChar::new('9').is_ascii_digit(), true);
assert_eq!(AsciiChar::new('a').is_ascii_digit(), false);
assert_eq!(AsciiChar::new('A').is_ascii_digit(), false);
assert_eq!(AsciiChar::new('/').is_ascii_digit(), false);
Sourcepub const fn is_alphanumeric(self) -> bool
pub const fn is_alphanumeric(self) -> bool
Check if the character is a letter or number
Sourcepub const fn is_ascii_alphanumeric(&self) -> bool
pub const fn is_ascii_alphanumeric(&self) -> bool
Check if the character is a letter or number
This method is identical to is_alphanumeric()
Sourcepub const fn is_ascii_blank(&self) -> bool
pub const fn is_ascii_blank(&self) -> bool
Check if the character is a space or horizontal tab
§Examples
assert!(AsciiChar::Space.is_ascii_blank());
assert!(AsciiChar::Tab.is_ascii_blank());
assert!(!AsciiChar::VT.is_ascii_blank());
assert!(!AsciiChar::LineFeed.is_ascii_blank());
assert!(!AsciiChar::CarriageReturn.is_ascii_blank());
assert!(!AsciiChar::FF.is_ascii_blank());
Sourcepub const fn is_whitespace(self) -> bool
pub const fn is_whitespace(self) -> bool
Check if the character one of ’ ’, ‘\t’, ‘\n’, ‘\r’, ‘\0xb’ (vertical tab) or ‘\0xc’ (form feed).
Sourcepub const fn is_ascii_whitespace(&self) -> bool
pub const fn is_ascii_whitespace(&self) -> bool
Check if the character is a ’ ’, ‘\t’, ‘\n’, ‘\r’ or ‘\0xc’ (form feed).
This method is NOT identical to is_whitespace()
.
Sourcepub const fn is_ascii_control(&self) -> bool
pub const fn is_ascii_control(&self) -> bool
Check if the character is a control character
§Examples
assert_eq!(AsciiChar::new('\0').is_ascii_control(), true);
assert_eq!(AsciiChar::new('n').is_ascii_control(), false);
assert_eq!(AsciiChar::new(' ').is_ascii_control(), false);
assert_eq!(AsciiChar::new('\n').is_ascii_control(), true);
assert_eq!(AsciiChar::new('\t').is_ascii_control(), true);
assert_eq!(AsciiChar::EOT.is_ascii_control(), true);
Sourcepub const fn is_ascii_graphic(&self) -> bool
pub const fn is_ascii_graphic(&self) -> bool
Checks if the character is printable (except space)
§Examples
assert_eq!(AsciiChar::new('n').is_ascii_graphic(), true);
assert_eq!(AsciiChar::new(' ').is_ascii_graphic(), false);
assert_eq!(AsciiChar::new('\n').is_ascii_graphic(), false);
Sourcepub const fn is_ascii_printable(&self) -> bool
pub const fn is_ascii_printable(&self) -> bool
Checks if the character is printable (including space)
§Examples
assert_eq!(AsciiChar::new('n').is_ascii_printable(), true);
assert_eq!(AsciiChar::new(' ').is_ascii_printable(), true);
assert_eq!(AsciiChar::new('\n').is_ascii_printable(), false);
Sourcepub const fn is_lowercase(self) -> bool
pub const fn is_lowercase(self) -> bool
Checks if the character is alphabetic and lowercase (a-z).
§Examples
use ascii::AsciiChar;
assert_eq!(AsciiChar::new('a').is_lowercase(), true);
assert_eq!(AsciiChar::new('A').is_lowercase(), false);
assert_eq!(AsciiChar::new('@').is_lowercase(), false);
Sourcepub const fn is_ascii_lowercase(&self) -> bool
pub const fn is_ascii_lowercase(&self) -> bool
Checks if the character is alphabetic and lowercase (a-z).
This method is identical to is_lowercase()
Sourcepub const fn is_uppercase(self) -> bool
pub const fn is_uppercase(self) -> bool
Checks if the character is alphabetic and uppercase (A-Z).
§Examples
assert_eq!(AsciiChar::new('A').is_uppercase(), true);
assert_eq!(AsciiChar::new('a').is_uppercase(), false);
assert_eq!(AsciiChar::new('@').is_uppercase(), false);
Sourcepub const fn is_ascii_uppercase(&self) -> bool
pub const fn is_ascii_uppercase(&self) -> bool
Checks if the character is alphabetic and uppercase (A-Z).
This method is identical to is_uppercase()
Sourcepub const fn is_ascii_punctuation(&self) -> bool
pub const fn is_ascii_punctuation(&self) -> bool
Checks if the character is punctuation
§Examples
assert_eq!(AsciiChar::new('n').is_ascii_punctuation(), false);
assert_eq!(AsciiChar::new(' ').is_ascii_punctuation(), false);
assert_eq!(AsciiChar::new('_').is_ascii_punctuation(), true);
assert_eq!(AsciiChar::new('~').is_ascii_punctuation(), true);
Sourcepub const fn is_ascii_hexdigit(&self) -> bool
pub const fn is_ascii_hexdigit(&self) -> bool
Checks if the character is a valid hex digit
§Examples
assert_eq!(AsciiChar::new('5').is_ascii_hexdigit(), true);
assert_eq!(AsciiChar::new('a').is_ascii_hexdigit(), true);
assert_eq!(AsciiChar::new('F').is_ascii_hexdigit(), true);
assert_eq!(AsciiChar::new('G').is_ascii_hexdigit(), false);
assert_eq!(AsciiChar::new(' ').is_ascii_hexdigit(), false);
Sourcepub fn as_printable_char(self) -> char
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!(AsciiChar::new('\0').as_printable_char(), '␀');
assert_eq!(AsciiChar::new('\n').as_printable_char(), '␊');
assert_eq!(AsciiChar::new(' ').as_printable_char(), ' ');
assert_eq!(AsciiChar::new('p').as_printable_char(), 'p');
Sourcepub fn make_ascii_uppercase(&mut self)
pub fn make_ascii_uppercase(&mut self)
Replaces letters a
to z
with A
to Z
Sourcepub fn make_ascii_lowercase(&mut self)
pub fn make_ascii_lowercase(&mut self)
Replaces letters A
to Z
with a
to z
Sourcepub const fn to_ascii_uppercase(&self) -> Self
pub const fn to_ascii_uppercase(&self) -> Self
Maps letters a-z to A-Z and returns any other character unchanged.
§Examples
assert_eq!(AsciiChar::new('u').to_ascii_uppercase().as_char(), 'U');
assert_eq!(AsciiChar::new('U').to_ascii_uppercase().as_char(), 'U');
assert_eq!(AsciiChar::new('2').to_ascii_uppercase().as_char(), '2');
assert_eq!(AsciiChar::new('=').to_ascii_uppercase().as_char(), '=');
assert_eq!(AsciiChar::new('[').to_ascii_uppercase().as_char(), '[');
Sourcepub const fn to_ascii_lowercase(&self) -> Self
pub const fn to_ascii_lowercase(&self) -> Self
Maps letters A-Z to a-z and returns any other character unchanged.
§Examples
assert_eq!(AsciiChar::new('U').to_ascii_lowercase().as_char(), 'u');
assert_eq!(AsciiChar::new('u').to_ascii_lowercase().as_char(), 'u');
assert_eq!(AsciiChar::new('2').to_ascii_lowercase().as_char(), '2');
assert_eq!(AsciiChar::new('^').to_ascii_lowercase().as_char(), '^');
assert_eq!(AsciiChar::new('\x7f').to_ascii_lowercase().as_char(), '\x7f');
Sourcepub const fn eq_ignore_ascii_case(&self, other: &Self) -> bool
pub const fn eq_ignore_ascii_case(&self, other: &Self) -> bool
Compares two characters case-insensitively.
Trait Implementations§
Source§impl From<AsciiChar> for AsciiString
impl From<AsciiChar> for AsciiString
Source§impl Ord for AsciiChar
impl Ord for AsciiChar
Source§impl PartialOrd<AsciiChar> for char
impl PartialOrd<AsciiChar> for char
Source§impl PartialOrd<AsciiChar> for u8
impl PartialOrd<AsciiChar> for u8
Source§impl PartialOrd<char> for AsciiChar
impl PartialOrd<char> for AsciiChar
Source§impl PartialOrd<u8> for AsciiChar
impl PartialOrd<u8> for AsciiChar
Source§impl PartialOrd for AsciiChar
impl PartialOrd for AsciiChar
Source§impl ToAsciiChar for AsciiChar
impl ToAsciiChar for AsciiChar
Source§fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError>
fn to_ascii_char(self) -> Result<AsciiChar, ToAsciiCharError>
AsciiChar
. Read moreSource§unsafe fn to_ascii_char_unchecked(self) -> AsciiChar
unsafe fn to_ascii_char_unchecked(self) -> AsciiChar
AsciiChar
without checking that it is an ASCII character. Read moreimpl Copy for AsciiChar
impl Eq for AsciiChar
impl StructuralPartialEq for AsciiChar
Auto Trait Implementations§
impl Freeze for AsciiChar
impl RefUnwindSafe for AsciiChar
impl Send for AsciiChar
impl Sync for AsciiChar
impl Unpin for AsciiChar
impl UnwindSafe for AsciiChar
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 1 byte
Size for each variant:
Null
: 0 bytesSOH
: 0 bytesSOX
: 0 bytesETX
: 0 bytesEOT
: 0 bytesENQ
: 0 bytesACK
: 0 bytesBell
: 0 bytesBackSpace
: 0 bytesTab
: 0 bytesLineFeed
: 0 bytesVT
: 0 bytesFF
: 0 bytesCarriageReturn
: 0 bytesSI
: 0 bytesSO
: 0 bytesDLE
: 0 bytesDC1
: 0 bytesDC2
: 0 bytesDC3
: 0 bytesDC4
: 0 bytesNAK
: 0 bytesSYN
: 0 bytesETB
: 0 bytesCAN
: 0 bytesEM
: 0 bytesSUB
: 0 bytesESC
: 0 bytesFS
: 0 bytesGS
: 0 bytesRS
: 0 bytesUS
: 0 bytesSpace
: 0 bytesExclamation
: 0 bytesQuotation
: 0 bytesHash
: 0 bytesDollar
: 0 bytesPercent
: 0 bytesAmpersand
: 0 bytesApostrophe
: 0 bytesParenOpen
: 0 bytesParenClose
: 0 bytesAsterisk
: 0 bytesPlus
: 0 bytesComma
: 0 bytesMinus
: 0 bytesDot
: 0 bytesSlash
: 0 bytes_0
: 0 bytes_1
: 0 bytes_2
: 0 bytes_3
: 0 bytes_4
: 0 bytes_5
: 0 bytes_6
: 0 bytes_7
: 0 bytes_8
: 0 bytes_9
: 0 bytesColon
: 0 bytesSemicolon
: 0 bytesLessThan
: 0 bytesEqual
: 0 bytesGreaterThan
: 0 bytesQuestion
: 0 bytesAt
: 0 bytesA
: 0 bytesB
: 0 bytesC
: 0 bytesD
: 0 bytesE
: 0 bytesF
: 0 bytesG
: 0 bytesH
: 0 bytesI
: 0 bytesJ
: 0 bytesK
: 0 bytesL
: 0 bytesM
: 0 bytesN
: 0 bytesO
: 0 bytesP
: 0 bytesQ
: 0 bytesR
: 0 bytesS
: 0 bytesT
: 0 bytesU
: 0 bytesV
: 0 bytesW
: 0 bytesX
: 0 bytesY
: 0 bytesZ
: 0 bytesBracketOpen
: 0 bytesBackSlash
: 0 bytesBracketClose
: 0 bytesCaret
: 0 bytesUnderScore
: 0 bytesGrave
: 0 bytesa
: 0 bytesb
: 0 bytesc
: 0 bytesd
: 0 bytese
: 0 bytesf
: 0 bytesg
: 0 bytesh
: 0 bytesi
: 0 bytesj
: 0 bytesk
: 0 bytesl
: 0 bytesm
: 0 bytesn
: 0 byteso
: 0 bytesp
: 0 bytesq
: 0 bytesr
: 0 bytess
: 0 bytest
: 0 bytesu
: 0 bytesv
: 0 bytesw
: 0 bytesx
: 0 bytesy
: 0 bytesz
: 0 bytesCurlyBraceOpen
: 0 bytesVerticalBar
: 0 bytesCurlyBraceClose
: 0 bytesTilde
: 0 bytesDEL
: 0 bytes