#[repr(u8)]pub enum Char {
Show 128 variants
Null,
StartOfHeading,
StartOfText,
EndOfText,
EndOfTransmission,
Enquiry,
Acknowledge,
Bell,
Backspace,
CharacterTabulation,
LineFeed,
LineTabulation,
FormFeed,
CarriageReturn,
ShiftOut,
ShiftIn,
DataLinkEscape,
DeviceControlOne,
DeviceControlTwo,
DeviceControlThree,
DeviceControlFour,
NegativeAcknowledge,
SynchronousIdle,
EndOfTransmissionBlock,
Cancel,
EndOfMedium,
Substitute,
Escape,
InformationSeparatorFour,
InformationSeparatorThree,
InformationSeparatorTwo,
InformationSeparatorOne,
Space,
ExclamationMark,
QuotationMark,
NumberSign,
DollarSign,
PercentSign,
Ampersand,
Apostrophe,
LeftParenthesis,
RightParenthesis,
Asterisk,
PlusSign,
Comma,
HyphenMinus,
FullStop,
Solidus,
Digit0,
Digit1,
Digit2,
Digit3,
Digit4,
Digit5,
Digit6,
Digit7,
Digit8,
Digit9,
Colon,
Semicolon,
LessThanSign,
EqualsSign,
GreaterThanSign,
QuestionMark,
CommercialAt,
CapitalA,
CapitalB,
CapitalC,
CapitalD,
CapitalE,
CapitalF,
CapitalG,
CapitalH,
CapitalI,
CapitalJ,
CapitalK,
CapitalL,
CapitalM,
CapitalN,
CapitalO,
CapitalP,
CapitalQ,
CapitalR,
CapitalS,
CapitalT,
CapitalU,
CapitalV,
CapitalW,
CapitalX,
CapitalY,
CapitalZ,
LeftSquareBracket,
ReverseSolidus,
RightSquareBracket,
CircumflexAccent,
LowLine,
GraveAccent,
SmallA,
SmallB,
SmallC,
SmallD,
SmallE,
SmallF,
SmallG,
SmallH,
SmallI,
SmallJ,
SmallK,
SmallL,
SmallM,
SmallN,
SmallO,
SmallP,
SmallQ,
SmallR,
SmallS,
SmallT,
SmallU,
SmallV,
SmallW,
SmallX,
SmallY,
SmallZ,
LeftCurlyBracket,
VerticalLine,
RightCurlyBracket,
Tilde,
Delete,
}
ascii_char
#110998)Expand description
One of the 128 Unicode characters from U+0000 through U+007F, often known as the ASCII subset.
Officially, this is the first block in Unicode, Basic Latin. For details, see the C0 Controls and Basic Latin code chart.
This block was based on older 7-bit character code standards such as ANSI X3.4-1977, ISO 646-1973, and NIST FIPS 1-2.
When to use this
The main advantage of this subset is that it’s always valid UTF-8. As such,
the &[ascii::Char]
-> &str
conversion function (as well as other related
ones) are O(1): no runtime checks are needed.
If you’re consuming strings, you should usually handle Unicode and thus
accept str
s, not limit yourself to ascii::Char
s.
However, certain formats are intentionally designed to produce ASCII-only
output in order to be 8-bit-clean. In those cases, it can be simpler and
faster to generate ascii::Char
s instead of dealing with the variable width
properties of general UTF-8 encoded strings, while still allowing the result
to be used freely with other Rust things that deal in general str
s.
For example, a UUID library might offer a way to produce the string
representation of a UUID as an [ascii::Char; 36]
to avoid memory
allocation yet still allow it to be used as UTF-8 via as_str
without
paying for validation (or needing unsafe
code) the way it would if it
were provided as a [u8; 36]
.
Layout
This type is guaranteed to have a size and alignment of 1 byte.
Names
The variants on this type are Unicode names of the characters in upper camel case, with a few tweaks:
- For
<control>
characters, the primary alias name is used. LATIN
is dropped, as this block has no non-latin letters.LETTER
is dropped, asCAPITAL
/SMALL
suffices in this block.DIGIT
s use a single digit rather than writing outZERO
,ONE
, etc.
Variants§
Null
ascii_char_variants
#110998)U+0000
StartOfHeading
ascii_char_variants
#110998)U+0001
StartOfText
ascii_char_variants
#110998)U+0002
EndOfText
ascii_char_variants
#110998)U+0003
EndOfTransmission
ascii_char_variants
#110998)U+0004
Enquiry
ascii_char_variants
#110998)U+0005
Acknowledge
ascii_char_variants
#110998)U+0006
Bell
ascii_char_variants
#110998)U+0007
Backspace
ascii_char_variants
#110998)U+0008
CharacterTabulation
ascii_char_variants
#110998)U+0009
LineFeed
ascii_char_variants
#110998)U+000A
LineTabulation
ascii_char_variants
#110998)U+000B
FormFeed
ascii_char_variants
#110998)U+000C
CarriageReturn
ascii_char_variants
#110998)U+000D
ShiftOut
ascii_char_variants
#110998)U+000E
ShiftIn
ascii_char_variants
#110998)U+000F
DataLinkEscape
ascii_char_variants
#110998)U+0010
DeviceControlOne
ascii_char_variants
#110998)U+0011
DeviceControlTwo
ascii_char_variants
#110998)U+0012
DeviceControlThree
ascii_char_variants
#110998)U+0013
DeviceControlFour
ascii_char_variants
#110998)U+0014
NegativeAcknowledge
ascii_char_variants
#110998)U+0015
SynchronousIdle
ascii_char_variants
#110998)U+0016
EndOfTransmissionBlock
ascii_char_variants
#110998)U+0017
Cancel
ascii_char_variants
#110998)U+0018
EndOfMedium
ascii_char_variants
#110998)U+0019
Substitute
ascii_char_variants
#110998)U+001A
Escape
ascii_char_variants
#110998)U+001B
InformationSeparatorFour
ascii_char_variants
#110998)U+001C
InformationSeparatorThree
ascii_char_variants
#110998)U+001D
InformationSeparatorTwo
ascii_char_variants
#110998)U+001E
InformationSeparatorOne
ascii_char_variants
#110998)U+001F
Space
ascii_char_variants
#110998)U+0020
ExclamationMark
ascii_char_variants
#110998)U+0021
QuotationMark
ascii_char_variants
#110998)U+0022
NumberSign
ascii_char_variants
#110998)U+0023
DollarSign
ascii_char_variants
#110998)U+0024
PercentSign
ascii_char_variants
#110998)U+0025
Ampersand
ascii_char_variants
#110998)U+0026
Apostrophe
ascii_char_variants
#110998)U+0027
LeftParenthesis
ascii_char_variants
#110998)U+0028
RightParenthesis
ascii_char_variants
#110998)U+0029
Asterisk
ascii_char_variants
#110998)U+002A
PlusSign
ascii_char_variants
#110998)U+002B
Comma
ascii_char_variants
#110998)U+002C
HyphenMinus
ascii_char_variants
#110998)U+002D
FullStop
ascii_char_variants
#110998)U+002E
Solidus
ascii_char_variants
#110998)U+002F
Digit0
ascii_char_variants
#110998)U+0030
Digit1
ascii_char_variants
#110998)U+0031
Digit2
ascii_char_variants
#110998)U+0032
Digit3
ascii_char_variants
#110998)U+0033
Digit4
ascii_char_variants
#110998)U+0034
Digit5
ascii_char_variants
#110998)U+0035
Digit6
ascii_char_variants
#110998)U+0036
Digit7
ascii_char_variants
#110998)U+0037
Digit8
ascii_char_variants
#110998)U+0038
Digit9
ascii_char_variants
#110998)U+0039
Colon
ascii_char_variants
#110998)U+003A
Semicolon
ascii_char_variants
#110998)U+003B
LessThanSign
ascii_char_variants
#110998)U+003C
EqualsSign
ascii_char_variants
#110998)U+003D
GreaterThanSign
ascii_char_variants
#110998)U+003E
QuestionMark
ascii_char_variants
#110998)U+003F
CommercialAt
ascii_char_variants
#110998)U+0040
CapitalA
ascii_char_variants
#110998)U+0041
CapitalB
ascii_char_variants
#110998)U+0042
CapitalC
ascii_char_variants
#110998)U+0043
CapitalD
ascii_char_variants
#110998)U+0044
CapitalE
ascii_char_variants
#110998)U+0045
CapitalF
ascii_char_variants
#110998)U+0046
CapitalG
ascii_char_variants
#110998)U+0047
CapitalH
ascii_char_variants
#110998)U+0048
CapitalI
ascii_char_variants
#110998)U+0049
CapitalJ
ascii_char_variants
#110998)U+004A
CapitalK
ascii_char_variants
#110998)U+004B
CapitalL
ascii_char_variants
#110998)U+004C
CapitalM
ascii_char_variants
#110998)U+004D
CapitalN
ascii_char_variants
#110998)U+004E
CapitalO
ascii_char_variants
#110998)U+004F
CapitalP
ascii_char_variants
#110998)U+0050
CapitalQ
ascii_char_variants
#110998)U+0051
CapitalR
ascii_char_variants
#110998)U+0052
CapitalS
ascii_char_variants
#110998)U+0053
CapitalT
ascii_char_variants
#110998)U+0054
CapitalU
ascii_char_variants
#110998)U+0055
CapitalV
ascii_char_variants
#110998)U+0056
CapitalW
ascii_char_variants
#110998)U+0057
CapitalX
ascii_char_variants
#110998)U+0058
CapitalY
ascii_char_variants
#110998)U+0059
CapitalZ
ascii_char_variants
#110998)U+005A
LeftSquareBracket
ascii_char_variants
#110998)U+005B
ReverseSolidus
ascii_char_variants
#110998)U+005C
RightSquareBracket
ascii_char_variants
#110998)U+005D
CircumflexAccent
ascii_char_variants
#110998)U+005E
LowLine
ascii_char_variants
#110998)U+005F
GraveAccent
ascii_char_variants
#110998)U+0060
SmallA
ascii_char_variants
#110998)U+0061
SmallB
ascii_char_variants
#110998)U+0062
SmallC
ascii_char_variants
#110998)U+0063
SmallD
ascii_char_variants
#110998)U+0064
SmallE
ascii_char_variants
#110998)U+0065
SmallF
ascii_char_variants
#110998)U+0066
SmallG
ascii_char_variants
#110998)U+0067
SmallH
ascii_char_variants
#110998)U+0068
SmallI
ascii_char_variants
#110998)U+0069
SmallJ
ascii_char_variants
#110998)U+006A
SmallK
ascii_char_variants
#110998)U+006B
SmallL
ascii_char_variants
#110998)U+006C
SmallM
ascii_char_variants
#110998)U+006D
SmallN
ascii_char_variants
#110998)U+006E
SmallO
ascii_char_variants
#110998)U+006F
SmallP
ascii_char_variants
#110998)U+0070
SmallQ
ascii_char_variants
#110998)U+0071
SmallR
ascii_char_variants
#110998)U+0072
SmallS
ascii_char_variants
#110998)U+0073
SmallT
ascii_char_variants
#110998)U+0074
SmallU
ascii_char_variants
#110998)U+0075
SmallV
ascii_char_variants
#110998)U+0076
SmallW
ascii_char_variants
#110998)U+0077
SmallX
ascii_char_variants
#110998)U+0078
SmallY
ascii_char_variants
#110998)U+0079
SmallZ
ascii_char_variants
#110998)U+007A
LeftCurlyBracket
ascii_char_variants
#110998)U+007B
VerticalLine
ascii_char_variants
#110998)U+007C
RightCurlyBracket
ascii_char_variants
#110998)U+007D
Tilde
ascii_char_variants
#110998)U+007E
Delete
ascii_char_variants
#110998)U+007F
Implementations§
source§impl AsciiChar
impl AsciiChar
sourcepub const fn from_u8(b: u8) -> Option<AsciiChar>
🔬This is a nightly-only experimental API. (ascii_char
#110998)
pub const fn from_u8(b: u8) -> Option<AsciiChar>
ascii_char
#110998)Creates an ascii character from the byte b
,
or returns None
if it’s too large.
sourcepub const unsafe fn from_u8_unchecked(b: u8) -> AsciiChar
🔬This is a nightly-only experimental API. (ascii_char
#110998)
pub const unsafe fn from_u8_unchecked(b: u8) -> AsciiChar
ascii_char
#110998)Creates an ASCII character from the byte b
,
without checking whether it’s valid.
Safety
b
must be in 0..=127
, or else this is UB.
sourcepub const fn digit(d: u8) -> Option<AsciiChar>
🔬This is a nightly-only experimental API. (ascii_char
#110998)
pub const fn digit(d: u8) -> Option<AsciiChar>
ascii_char
#110998)When passed the number 0
, 1
, …, 9
, returns the character
'0'
, '1'
, …, '9'
respectively.
If d >= 10
, returns None
.
sourcepub const unsafe fn digit_unchecked(d: u8) -> AsciiChar
🔬This is a nightly-only experimental API. (ascii_char
#110998)
pub const unsafe fn digit_unchecked(d: u8) -> AsciiChar
ascii_char
#110998)When passed the number 0
, 1
, …, 9
, returns the character
'0'
, '1'
, …, '9'
respectively, without checking that it’s in-range.
Safety
This is immediate UB if called with d > 64
.
If d >= 10
and d <= 64
, this is allowed to return any value or panic.
Notably, it should not be expected to return hex digits, or any other
reasonable extension of the decimal digits.
(This lose safety condition is intended to simplify soundness proofs when writing code using this method, since the implementation doesn’t need something really specific, not to make those other arguments do something useful. It might be tightened before stabilization.)
sourcepub const fn as_u8(self) -> u8
🔬This is a nightly-only experimental API. (ascii_char
#110998)
pub const fn as_u8(self) -> u8
ascii_char
#110998)Gets this ASCII character as a byte.
Trait Implementations§
source§impl Ord for AsciiChar
impl Ord for AsciiChar
source§impl PartialEq<AsciiChar> for AsciiChar
impl PartialEq<AsciiChar> for AsciiChar
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 more