Enum core::ascii::Char

source ·
#[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,
}
🔬This is a nightly-only experimental API. (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 strs, not limit yourself to ascii::Chars.

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::Chars 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 strs.

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, as CAPITAL/SMALL suffices in this block.
  • DIGITs use a single digit rather than writing out ZERO, ONE, etc.

Variants§

§

Null

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0000

§

StartOfHeading

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0001

§

StartOfText

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0002

§

EndOfText

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0003

§

EndOfTransmission

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0004

§

Enquiry

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0005

§

Acknowledge

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0006

§

Bell

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0007

§

Backspace

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0008

§

CharacterTabulation

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0009

§

LineFeed

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+000A

§

LineTabulation

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+000B

§

FormFeed

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+000C

§

CarriageReturn

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+000D

§

ShiftOut

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+000E

§

ShiftIn

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+000F

§

DataLinkEscape

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0010

§

DeviceControlOne

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0011

§

DeviceControlTwo

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0012

§

DeviceControlThree

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0013

§

DeviceControlFour

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0014

§

NegativeAcknowledge

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0015

§

SynchronousIdle

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0016

§

EndOfTransmissionBlock

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0017

§

Cancel

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0018

§

EndOfMedium

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0019

§

Substitute

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+001A

§

Escape

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+001B

§

InformationSeparatorFour

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+001C

§

InformationSeparatorThree

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+001D

§

InformationSeparatorTwo

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+001E

§

InformationSeparatorOne

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+001F

§

Space

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0020

§

ExclamationMark

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0021

§

QuotationMark

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0022

§

NumberSign

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0023

§

DollarSign

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0024

§

PercentSign

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0025

§

Ampersand

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0026

§

Apostrophe

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0027

§

LeftParenthesis

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0028

§

RightParenthesis

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0029

§

Asterisk

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+002A

§

PlusSign

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+002B

§

Comma

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+002C

§

HyphenMinus

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+002D

§

FullStop

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+002E

§

Solidus

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+002F

§

Digit0

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0030

§

Digit1

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0031

§

Digit2

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0032

§

Digit3

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0033

§

Digit4

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0034

§

Digit5

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0035

§

Digit6

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0036

§

Digit7

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0037

§

Digit8

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0038

§

Digit9

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0039

§

Colon

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+003A

§

Semicolon

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+003B

§

LessThanSign

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+003C

§

EqualsSign

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+003D

§

GreaterThanSign

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+003E

§

QuestionMark

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+003F

§

CommercialAt

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0040

§

CapitalA

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0041

§

CapitalB

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0042

§

CapitalC

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0043

§

CapitalD

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0044

§

CapitalE

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0045

§

CapitalF

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0046

§

CapitalG

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0047

§

CapitalH

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0048

§

CapitalI

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0049

§

CapitalJ

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+004A

§

CapitalK

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+004B

§

CapitalL

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+004C

§

CapitalM

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+004D

§

CapitalN

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+004E

§

CapitalO

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+004F

§

CapitalP

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0050

§

CapitalQ

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0051

§

CapitalR

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0052

§

CapitalS

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0053

§

CapitalT

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0054

§

CapitalU

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0055

§

CapitalV

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0056

§

CapitalW

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0057

§

CapitalX

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0058

§

CapitalY

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0059

§

CapitalZ

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+005A

§

LeftSquareBracket

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+005B

§

ReverseSolidus

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+005C

§

RightSquareBracket

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+005D

§

CircumflexAccent

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+005E

§

LowLine

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+005F

§

GraveAccent

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0060

§

SmallA

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0061

§

SmallB

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0062

§

SmallC

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0063

§

SmallD

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0064

§

SmallE

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0065

§

SmallF

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0066

§

SmallG

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0067

§

SmallH

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0068

§

SmallI

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0069

§

SmallJ

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+006A

§

SmallK

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+006B

§

SmallL

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+006C

§

SmallM

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+006D

§

SmallN

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+006E

§

SmallO

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+006F

§

SmallP

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0070

§

SmallQ

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0071

§

SmallR

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0072

§

SmallS

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0073

§

SmallT

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0074

§

SmallU

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0075

§

SmallV

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0076

§

SmallW

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0077

§

SmallX

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0078

§

SmallY

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+0079

§

SmallZ

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+007A

§

LeftCurlyBracket

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+007B

§

VerticalLine

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+007C

§

RightCurlyBracket

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+007D

§

Tilde

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+007E

§

Delete

🔬This is a nightly-only experimental API. (ascii_char_variants #110998)

U+007F

Implementations§

source§

impl AsciiChar

source

pub const fn from_u8(b: u8) -> Option<Self>

🔬This is a nightly-only experimental API. (ascii_char #110998)

Creates an ascii character from the byte b, or returns None if it’s too large.

source

pub const unsafe fn from_u8_unchecked(b: u8) -> Self

🔬This is a nightly-only experimental API. (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.

source

pub const fn digit(d: u8) -> Option<Self>

🔬This is a nightly-only experimental API. (ascii_char #110998)

When passed the number 0, 1, …, 9, returns the character '0', '1', …, '9' respectively.

If d >= 10, returns None.

source

pub const unsafe fn digit_unchecked(d: u8) -> Self

🔬This is a nightly-only experimental API. (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.)

source

pub const fn as_u8(self) -> u8

🔬This is a nightly-only experimental API. (ascii_char #110998)

Gets this ASCII character as a byte.

source

pub const fn as_char(self) -> char

🔬This is a nightly-only experimental API. (ascii_char #110998)

Gets this ASCII character as a char Unicode Scalar Value.

source

pub const fn as_str(&self) -> &str

🔬This is a nightly-only experimental API. (ascii_char #110998)

Views this ASCII character as a one-code-unit UTF-8 str.

Trait Implementations§

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 Display for AsciiChar

source§

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

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

impl Eq for AsciiChar

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: Hasher>(data: &[Self], state: &mut H)where 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) -> Selfwhere Self: Sized,

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

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

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

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd,

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

impl PartialEq<AsciiChar> for AsciiChar

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<AsciiChar> 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

This method 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

This method 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

This method 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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Copy for AsciiChar

source§

impl StructuralEq for AsciiChar

source§

impl StructuralPartialEq for AsciiChar

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. 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 Twhere 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> SizedTypeProperties for T

source§

const IS_ZST: bool = _

🔬This is a nightly-only experimental API. (sized_type_properties)
true if this type requires no storage. false if its size is greater than zero. Read more
source§

impl<T> SpecOptionPartialEq for Twhere T: PartialEq<T>,

source§

default fn eq(l: &Option<T>, r: &Option<T>) -> bool

🔬This is a nightly-only experimental API. (spec_option_partial_eq)
source§

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

§

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 Twhere U: TryFrom<T>,

§

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.
source§

impl<T> Printable for Twhere T: Copy + Debug,