#[repr(u8)]pub enum AsciiChar {
Show 128 variants
Null = 0,
StartOfHeading = 1,
StartOfText = 2,
EndOfText = 3,
EndOfTransmission = 4,
Enquiry = 5,
Acknowledge = 6,
Bell = 7,
Backspace = 8,
AsciiCharacterTabulation = 9,
LineFeed = 10,
LineTabulation = 11,
FormFeed = 12,
CarriageReturn = 13,
ShiftOut = 14,
ShiftIn = 15,
DataLinkEscape = 16,
DeviceControlOne = 17,
DeviceControlTwo = 18,
DeviceControlThree = 19,
DeviceControlFour = 20,
NegativeAcknowledge = 21,
SynchronousIdle = 22,
EndOfTransmissionBlock = 23,
Cancel = 24,
EndOfMedium = 25,
Substitute = 26,
Escape = 27,
InformationSeparatorFour = 28,
InformationSeparatorThree = 29,
InformationSeparatorTwo = 30,
InformationSeparatorOne = 31,
Space = 32,
ExclamationMark = 33,
QuotationMark = 34,
NumberSign = 35,
DollarSign = 36,
PercentSign = 37,
Ampersand = 38,
Apostrophe = 39,
LeftParenthesis = 40,
RightParenthesis = 41,
Asterisk = 42,
PlusSign = 43,
Comma = 44,
HyphenMinus = 45,
FullStop = 46,
Solidus = 47,
Digit0 = 48,
Digit1 = 49,
Digit2 = 50,
Digit3 = 51,
Digit4 = 52,
Digit5 = 53,
Digit6 = 54,
Digit7 = 55,
Digit8 = 56,
Digit9 = 57,
Colon = 58,
Semicolon = 59,
LessThanSign = 60,
EqualsSign = 61,
GreaterThanSign = 62,
QuestionMark = 63,
CommercialAt = 64,
CapitalA = 65,
CapitalB = 66,
CapitalC = 67,
CapitalD = 68,
CapitalE = 69,
CapitalF = 70,
CapitalG = 71,
CapitalH = 72,
CapitalI = 73,
CapitalJ = 74,
CapitalK = 75,
CapitalL = 76,
CapitalM = 77,
CapitalN = 78,
CapitalO = 79,
CapitalP = 80,
CapitalQ = 81,
CapitalR = 82,
CapitalS = 83,
CapitalT = 84,
CapitalU = 85,
CapitalV = 86,
CapitalW = 87,
CapitalX = 88,
CapitalY = 89,
CapitalZ = 90,
LeftSquareBracket = 91,
ReverseSolidus = 92,
RightSquareBracket = 93,
CircumflexAccent = 94,
LowLine = 95,
GraveAccent = 96,
SmallA = 97,
SmallB = 98,
SmallC = 99,
SmallD = 100,
SmallE = 101,
SmallF = 102,
SmallG = 103,
SmallH = 104,
SmallI = 105,
SmallJ = 106,
SmallK = 107,
SmallL = 108,
SmallM = 109,
SmallN = 110,
SmallO = 111,
SmallP = 112,
SmallQ = 113,
SmallR = 114,
SmallS = 115,
SmallT = 116,
SmallU = 117,
SmallV = 118,
SmallW = 119,
SmallX = 120,
SmallY = 121,
SmallZ = 122,
LeftCurlyBracket = 123,
VerticalLine = 124,
RightCurlyBracket = 125,
Tilde = 126,
Delete = 127,
}
ascii
only.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::AsciiChar]
-> &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::AsciiChar
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::AsciiChar
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::AsciiChar; 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 = 0
U+0000 (Default variant)
StartOfHeading = 1
U+0001
StartOfText = 2
U+0002
EndOfText = 3
U+0003
EndOfTransmission = 4
U+0004
Enquiry = 5
U+0005
Acknowledge = 6
U+0006
Bell = 7
U+0007
Backspace = 8
U+0008
AsciiCharacterTabulation = 9
U+0009
LineFeed = 10
U+000A
LineTabulation = 11
U+000B
FormFeed = 12
U+000C
CarriageReturn = 13
U+000D
ShiftOut = 14
U+000E
ShiftIn = 15
U+000F
DataLinkEscape = 16
U+0010
DeviceControlOne = 17
U+0011
DeviceControlTwo = 18
U+0012
DeviceControlThree = 19
U+0013
DeviceControlFour = 20
U+0014
NegativeAcknowledge = 21
U+0015
SynchronousIdle = 22
U+0016
EndOfTransmissionBlock = 23
U+0017
Cancel = 24
U+0018
EndOfMedium = 25
U+0019
Substitute = 26
U+001A
Escape = 27
U+001B
InformationSeparatorFour = 28
U+001C
InformationSeparatorThree = 29
U+001D
InformationSeparatorTwo = 30
U+001E
InformationSeparatorOne = 31
U+001F
Space = 32
U+0020
ExclamationMark = 33
U+0021
QuotationMark = 34
U+0022
NumberSign = 35
U+0023
DollarSign = 36
U+0024
PercentSign = 37
U+0025
Ampersand = 38
U+0026
Apostrophe = 39
U+0027
LeftParenthesis = 40
U+0028
RightParenthesis = 41
U+0029
Asterisk = 42
U+002A
PlusSign = 43
U+002B
Comma = 44
U+002C
HyphenMinus = 45
U+002D
FullStop = 46
U+002E
Solidus = 47
U+002F
Digit0 = 48
U+0030
Digit1 = 49
U+0031
Digit2 = 50
U+0032
Digit3 = 51
U+0033
Digit4 = 52
U+0034
Digit5 = 53
U+0035
Digit6 = 54
U+0036
Digit7 = 55
U+0037
Digit8 = 56
U+0038
Digit9 = 57
U+0039
Colon = 58
U+003A
Semicolon = 59
U+003B
LessThanSign = 60
U+003C
EqualsSign = 61
U+003D
GreaterThanSign = 62
U+003E
QuestionMark = 63
U+003F
CommercialAt = 64
U+0040
CapitalA = 65
U+0041
CapitalB = 66
U+0042
CapitalC = 67
U+0043
CapitalD = 68
U+0044
CapitalE = 69
U+0045
CapitalF = 70
U+0046
CapitalG = 71
U+0047
CapitalH = 72
U+0048
CapitalI = 73
U+0049
CapitalJ = 74
U+004A
CapitalK = 75
U+004B
CapitalL = 76
U+004C
CapitalM = 77
U+004D
CapitalN = 78
U+004E
CapitalO = 79
U+004F
CapitalP = 80
U+0050
CapitalQ = 81
U+0051
CapitalR = 82
U+0052
CapitalS = 83
U+0053
CapitalT = 84
U+0054
CapitalU = 85
U+0055
CapitalV = 86
U+0056
CapitalW = 87
U+0057
CapitalX = 88
U+0058
CapitalY = 89
U+0059
CapitalZ = 90
U+005A
LeftSquareBracket = 91
U+005B
ReverseSolidus = 92
U+005C
RightSquareBracket = 93
U+005D
CircumflexAccent = 94
U+005E
LowLine = 95
U+005F
GraveAccent = 96
U+0060
SmallA = 97
U+0061
SmallB = 98
U+0062
SmallC = 99
U+0063
SmallD = 100
U+0064
SmallE = 101
U+0065
SmallF = 102
U+0066
SmallG = 103
U+0067
SmallH = 104
U+0068
SmallI = 105
U+0069
SmallJ = 106
U+006A
SmallK = 107
U+006B
SmallL = 108
U+006C
SmallM = 109
U+006D
SmallN = 110
U+006E
SmallO = 111
U+006F
SmallP = 112
U+0070
SmallQ = 113
U+0071
SmallR = 114
U+0072
SmallS = 115
U+0073
SmallT = 116
U+0074
SmallU = 117
U+0075
SmallV = 118
U+0076
SmallW = 119
U+0077
SmallX = 120
U+0078
SmallY = 121
U+0079
SmallZ = 122
U+007A
LeftCurlyBracket = 123
U+007B
VerticalLine = 124
U+007C
RightCurlyBracket = 125
U+007D
Tilde = 126
U+007E
Delete = 127
U+007F
Implementations§
Source§impl AsciiChar
impl AsciiChar
Sourcepub const fn from_u8(b: u8) -> Option<Self> ⓘ
pub const fn from_u8(b: u8) -> Option<Self> ⓘ
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) -> Self
Available on crate feature unsafe_str
only.
pub const unsafe fn from_u8_unchecked(b: u8) -> Self
unsafe_str
only.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<Self> ⓘ
pub const fn digit(d: u8) -> Option<Self> ⓘ
When passed the number 0
, 1
, …, 9
, returns the character
'0'
, '1'
, …, '9'
respectively.
If d >= 10
, returns None
.
§Features
Uses unsafe_hint
for performance optimizations.
Sourcepub const unsafe fn digit_unchecked(d: u8) -> Self
Available on crate feature unsafe_str
only.
pub const unsafe fn digit_unchecked(d: u8) -> Self
unsafe_str
only.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.)
Source§impl AsciiChar
impl AsciiChar
Sourcepub const fn slice_as_str(slice: &[AsciiChar]) -> &str ⓘ
Available on crate feature unsafe_str
only.
pub const fn slice_as_str(slice: &[AsciiChar]) -> &str ⓘ
unsafe_str
only.Views a slice of ASCII characters as a UTF-8 str
.
Sourcepub const fn slice_as_bytes(slice: &[AsciiChar]) -> &[u8] ⓘ
Available on crate feature unsafe_str
only.
pub const fn slice_as_bytes(slice: &[AsciiChar]) -> &[u8] ⓘ
unsafe_str
only.Views a slice of ASCII characters as a slice of u8
bytes.
Trait Implementations§
Source§impl BitSized<7> for AsciiChar
impl BitSized<7> for AsciiChar
Source§const BIT_SIZE: usize = _
const BIT_SIZE: usize = _
Source§const MIN_BYTE_SIZE: usize = _
const MIN_BYTE_SIZE: usize = _
Source§impl ConstDefault for AsciiChar
impl ConstDefault for AsciiChar
Source§impl Ord for AsciiChar
impl Ord for AsciiChar
Source§impl PartialOrd for AsciiChar
impl PartialOrd for AsciiChar
impl 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§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize ⓘ
fn byte_align(&self) -> usize ⓘ
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of_val(&self) -> usize ⓘ
fn mem_align_of_val(&self) -> usize ⓘ
Source§fn mem_size_of_val(&self) -> usize ⓘ
fn mem_size_of_val(&self) -> usize ⓘ
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more§impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
impl<F, T> IntoSample<T> for Fwhere
T: FromSample<F>,
fn into_sample(self) -> T
§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError> ⓘ
§impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
§unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool
§fn resolve_niched(out: Place<NichedOption<T, N1>>)
fn resolve_niched(out: Place<NichedOption<T, N1>>)
out
indicating that a T
is niched.