Enum std::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

从 U+0000 到 U+007F 的 128 个 Unicode 字符之一,通常称为 ASCII 子集。

正式地,这是 Unicode Basic Latin 中的第一个 block。 详见 C0 Controls and Basic Latin 代码表。

此块基于较旧的 7 位字符代码标准,例如 ANSI X3.4-1977、ISO 646-1973 和 NIST FIPS 1-2

什么时候使用这个

这个子集的主要优点是它总是有效的 UTF-8。 因此,&[ascii::Char] -> &str 转换函数 (以及其他相关函数) 是 O(1): 不需要运行时检查。

如果您正在使用字符串,您通常应该处理 Unicode 并因此接受 str,而不是将自己限制为 ascii::Char。

但是,某些格式被有意设计为仅生成 ASCII 输出,以便 8 位干净。 在这些情况下,生成 ascii::Char 而不是处理一般 UTF-8 编码字符串的可变宽度属性会更简单、更快,同时仍然允许结果与其他 Rust 事物自由使用,这些事物通常处理 strs。

例如,UUID 库可能会提供一种方法来将 UUID 的字符串表示形式生成为 [ascii::Char; 36],以避免内存分配,但仍允许它通过 as_str 用作 UTF-8,而无需像以前那样支付验证费用 (或需要 unsafe 代码) 如果它作为 [u8; 36] 提供。

Layout

此类型保证具有 1 个字节的大小和对齐方式。

Names

这种类型的变体是大驼峰字母 Unicode names,有一些调整:

  • 对于 <control> 字符,使用主别名。
  • LATIN 是丢弃,因为这个块没有非拉丁字母。
  • LETTER 是抛弃,因为 CAPITAL/SMALL 在这个块中就足够了。
  • DIGIT 使用单个数字而不是写出 ZEROONE 等。

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

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

从字节 b 创建一个 ascii 字符,如果它太大则返回 None

source

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

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

从字节 b 创建一个 ASCII 字符,而不检查它是否有效。

Safety

b 必须在 0..=127 中,否则就是 UB。

source

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

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

当传递number 0, 1,…, 9 时,分别返回character '0', '1',…, '9'

如果是 d >= 10,则返回 None

source

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

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

当传递number 01、…、9 时,分别返回character '0''1'、…、'9',而不检查它是否在范围内。

Safety

如果用 d > 64 调用,这是 immediate UB。

如果 d >= 10d <= 64,则允许返回任何值或出现错误。 值得注意的是,不应期望返回十六进制数字或十进制数字的任何其他合理扩展。

(这种失去安全条件的目的是在使用这种方法编写代码时简化可靠性证明,因为实现不需要真正具体的东西,而不是让其他参数做一些有用的事情。 它可能会在稳定之前收紧。)

source

pub const fn as_u8(self) -> u8

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

获取此 ASCII 字符作为一个字节。

source

pub const fn as_char(self) -> char

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

获取此 ASCII 字符作为 char Unicode 标量值。

source

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

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

将此 ASCII 字符视为单码 - 元 UTF-8 str

Trait Implementations§

source§

impl Clone for AsciiChar

source§

fn clone(&self) -> AsciiChar

返回值的副本。 Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

source 执行复制分配。 Read more
source§

impl Debug for AsciiChar

source§

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

使用给定的格式化程序格式化该值。 Read more
source§

impl Display for AsciiChar

source§

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

使用给定的格式化程序格式化该值。 Read more
source§

impl Hash for AsciiChar

source§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

将该值输入给定的 HasherRead more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

将这种类型的切片送入给定的 Hasher 中。 Read more
source§

impl Ord for AsciiChar

source§

fn cmp(&self, other: &AsciiChar) -> Ordering

此方法返回 selfother 之间的 OrderingRead more
1.21.0 · source§

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

比较并返回两个值中的最大值。 Read more
1.21.0 · source§

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

比较并返回两个值中的最小值。 Read more
1.50.0 · source§

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

将值限制在某个时间间隔内。 Read more
source§

impl PartialEq<AsciiChar> for AsciiChar

source§

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

此方法测试 selfother 值是否相等,并由 == 使用。
1.0.0 · source§

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

此方法测试 !=。 默认实现几乎总是足够的,并且不应在没有充分理由的情况下被覆盖。
source§

impl PartialOrd<AsciiChar> for AsciiChar

source§

fn partial_cmp(&self, other: &AsciiChar) -> Option<Ordering>

如果存在,则此方法返回 selfother 值之间的顺序。 Read more
1.0.0 · source§

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

此方法测试的内容少于 (对于 selfother),并且由 < 操作员使用。 Read more
1.0.0 · source§

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

此方法测试小于或等于 (对于 selfother),并且由 <= 运算符使用。 Read more
1.0.0 · source§

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

此方法测试大于 (对于 selfother),并且由 > 操作员使用。 Read more
1.0.0 · source§

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

此方法测试是否大于或等于 (对于 selfother),并且由 >= 运算符使用。 Read more
source§

impl ToString for AsciiChar

source§

fn to_string(&self) -> String

将给定值转换为 StringRead more
source§

impl Copy for AsciiChar

source§

impl Eq 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

获取 selfTypeIdRead more
source§

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

source§

fn borrow(&self) -> &T

从拥有的值中一成不变地借用。 Read more
source§

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

source§

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

从拥有的值中借用。 Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

返回未更改的参数。

source§

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

source§

fn into(self) -> U

调用 U::from(self)

也就是说,这种转换是 From<T> for U 实现选择执行的任何操作。

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

获得所有权后的结果类型。
source§

fn to_owned(&self) -> T

从借用的数据创建拥有的数据,通常是通过克隆。 Read more
source§

fn clone_into(&self, target: &mut T)

使用借来的数据来替换拥有的数据,通常是通过克隆。 Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

将给定值转换为 StringRead more
source§

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

§

type Error = Infallible

发生转换错误时返回的类型。
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

执行转换。
source§

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

§

type Error = <U as TryFrom<T>>::Error

发生转换错误时返回的类型。
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。