#[repr(u8)]
pub enum AsciiChar {
Show 128 variants
Null,
SOH,
SOX,
ETX,
EOT,
ENQ,
ACK,
Bell,
BackSpace,
Tab,
LineFeed,
VT,
FF,
CarriageReturn,
SI,
SO,
DLE,
DC1,
DC2,
DC3,
DC4,
NAK,
SYN,
ETB,
CAN,
EM,
SUB,
ESC,
FS,
GS,
RS,
US,
Space,
Exclamation,
Quotation,
Hash,
Dollar,
Percent,
Ampersand,
Apostrophe,
ParenOpen,
ParenClose,
Asterisk,
Plus,
Comma,
Minus,
Dot,
Slash,
_0,
_1,
_2,
_3,
_4,
_5,
_6,
_7,
_8,
_9,
Colon,
Semicolon,
LessThan,
Equal,
GreaterThan,
Question,
At,
A,
B,
C,
D,
E,
F,
G,
H,
I,
J,
K,
L,
M,
N,
O,
P,
Q,
R,
S,
T,
U,
V,
W,
X,
Y,
Z,
BracketOpen,
BackSlash,
BracketClose,
Caret,
UnderScore,
Grave,
a,
b,
c,
d,
e,
f,
g,
h,
i,
j,
k,
l,
m,
n,
o,
p,
q,
r,
s,
t,
u,
v,
w,
x,
y,
z,
CurlyBraceOpen,
VerticalBar,
CurlyBraceClose,
Tilde,
DEL,
}
Expand description
An ASCII character. It wraps a u8
, with the highest bit always zero.
Variants§
Null
'\0'
SOH
SOX
ETX
EOT
ENQ
ACK
Bell
'\a'
is not recognized by Rust.
BackSpace
'\b'
is not recognized by Rust.
Tab
'\t'
LineFeed
'\n'
VT
'\v'
is not recognized by Rust.
FF
'\f'
is not recognized by Rust.
CarriageReturn
'\r'
SI
SO
DLE
DC1
DC2
Device control 2
DC3
Device control 3, Often XOFF
DC4
Device control 4
NAK
SYN
ETB
CAN
EM
SUB
ESC
'\e'
is not recognized by Rust.
FS
GS
RS
US
Space
' '
Exclamation
'!'
Quotation
'"'
Hash
'#'
Dollar
'$'
Percent
'%'
Ampersand
'&'
Apostrophe
'\''
ParenOpen
'('
ParenClose
')'
Asterisk
'*'
Plus
'+'
Comma
','
Minus
'-'
Dot
'.'
Slash
'/'
_0
'0'
_1
'1'
_2
'2'
_3
'3'
_4
'4'
_5
'5'
_6
'6'
_7
'7'
_8
'8'
_9
'9'
Colon
':'
Semicolon
';'
LessThan
'<'
Equal
'='
GreaterThan
'>'
Question
'?'
At
'@'
A
'A'
B
'B'
C
'C'
D
'D'
E
'E'
F
'F'
G
'G'
H
'H'
I
'I'
J
'J'
K
'K'
L
'L'
M
'M'
N
'N'
O
'O'
P
'P'
Q
'Q'
R
'R'
S
'S'
T
'T'
U
'U'
V
'V'
W
'W'
X
'X'
Y
'Y'
Z
'Z'
BracketOpen
'['
BackSlash
'\'
BracketClose
']'
Caret
'_'
UnderScore
'_'
Grave
'
’`
a
'a'
b
'b'
c
'c'
d
'd'
e
'e'
f
'f'
g
'g'
h
'h'
i
'i'
j
'j'
k
'k'
l
'l'
m
'm'
n
'n'
o
'o'
p
'p'
q
'q'
r
'r'
s
's'
t
't'
u
'u'
v
'v'
w
'w'
x
'x'
y
'y'
z
'z'
CurlyBraceOpen
'{'
VerticalBar
'|'
CurlyBraceClose
'}'
Tilde
'~'
DEL
Implementations§
source§impl AsciiChar
impl AsciiChar
sourcepub fn from<C: ToAsciiChar>(ch: C) -> Result<Self, ToAsciiCharError>
pub fn from<C: ToAsciiChar>(ch: C) -> Result<Self, ToAsciiCharError>
sourcepub unsafe fn from_unchecked<C: ToAsciiChar>(ch: C) -> Self
pub unsafe fn from_unchecked<C: ToAsciiChar>(ch: C) -> Self
Constructs an ASCII character from a char
or u8
without any checks.
sourcepub fn is_alphabetic(self) -> bool
pub fn is_alphabetic(self) -> bool
Check if the character is a letter (a-z, A-Z)
sourcepub fn is_alphanumeric(self) -> bool
pub fn is_alphanumeric(self) -> bool
Check if the character is a letter or number
sourcepub fn is_whitespace(self) -> bool
pub fn is_whitespace(self) -> bool
Check if the character is a ’ ’, ‘\t’, ‘\n’ or ‘\r’
sourcepub fn is_control(self) -> bool
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);
sourcepub fn is_graph(self) -> bool
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);
sourcepub fn is_print(self) -> bool
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);
sourcepub fn is_lowercase(self) -> bool
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);
sourcepub fn is_uppercase(self) -> bool
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);
sourcepub fn is_punctuation(self) -> bool
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);
sourcepub fn is_hex(self) -> bool
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);
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!('\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');
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 fn to_ascii_uppercase(&self) -> Self
pub fn to_ascii_uppercase(&self) -> Self
Maps letters a
…z
to A
…Z
and returns everything else unchanged.
sourcepub fn to_ascii_lowercase(&self) -> Self
pub fn to_ascii_lowercase(&self) -> Self
Maps letters A
…Z
to a
…z
and returns everything else unchanged.
sourcepub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
pub fn eq_ignore_ascii_case(&self, other: &Self) -> bool
Compares two characters case-insensitively.
Trait Implementations§
source§impl AsciiExt for AsciiChar
impl AsciiExt for AsciiChar
§type Owned = AsciiChar
type Owned = AsciiChar
source§fn is_ascii(&self) -> bool
fn is_ascii(&self) -> bool
source§fn to_ascii_uppercase(&self) -> AsciiChar
fn to_ascii_uppercase(&self) -> AsciiChar
source§fn to_ascii_lowercase(&self) -> AsciiChar
fn to_ascii_lowercase(&self) -> AsciiChar
source§fn eq_ignore_ascii_case(&self, other: &Self) -> bool
fn eq_ignore_ascii_case(&self, other: &Self) -> bool
source§fn make_ascii_uppercase(&mut self)
fn make_ascii_uppercase(&mut self)
source§fn make_ascii_lowercase(&mut self)
fn make_ascii_lowercase(&mut self)
source§impl<'a> Extend<&'a AsciiChar> for AsciiString
impl<'a> Extend<&'a AsciiChar> for AsciiString
source§fn extend<I: IntoIterator<Item = &'a AsciiChar>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = &'a AsciiChar>>(&mut self, iter: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl Extend<AsciiChar> for AsciiString
impl Extend<AsciiChar> for AsciiString
source§fn extend<I: IntoIterator<Item = AsciiChar>>(&mut self, iterable: I)
fn extend<I: IntoIterator<Item = AsciiChar>>(&mut self, iterable: I)
source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)source§impl FromIterator<AsciiChar> for AsciiString
impl FromIterator<AsciiChar> for AsciiString
source§fn from_iter<I: IntoIterator<Item = AsciiChar>>(iter: I) -> AsciiString
fn from_iter<I: IntoIterator<Item = AsciiChar>>(iter: I) -> AsciiString
source§impl Ord for AsciiChar
impl Ord for AsciiChar
source§impl PartialEq<AsciiChar> for AsciiChar
impl PartialEq<AsciiChar> for AsciiChar
source§impl PartialEq<AsciiChar> for char
impl PartialEq<AsciiChar> for char
source§impl PartialEq<AsciiChar> for u8
impl PartialEq<AsciiChar> for u8
source§impl PartialOrd<AsciiChar> for AsciiChar
impl PartialOrd<AsciiChar> for AsciiChar
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<AsciiChar> for char
impl PartialOrd<AsciiChar> for char
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<AsciiChar> for u8
impl PartialOrd<AsciiChar> for u8
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<char> for AsciiChar
impl PartialOrd<char> for AsciiChar
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§impl PartialOrd<u8> for AsciiChar
impl PartialOrd<u8> for AsciiChar
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moresource§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
.source§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.