Char

Enum Char 

Source
#[repr(u8)]
pub enum Char {
Show 128 variants Null = 0, StartOfHeading = 1, StartOfText = 2, EndOfText = 3, EndOfTransmission = 4, Enquiry = 5, Acknowledge = 6, Bell = 7, Backspace = 8, CharacterTabulation = 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,
}
🔬This is a nightly-only experimental API. (ascii_char)
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 = 0

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

U+0000 (The default variant)

§

StartOfHeading = 1

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

U+0001

§

StartOfText = 2

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

U+0002

§

EndOfText = 3

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

U+0003

§

EndOfTransmission = 4

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

U+0004

§

Enquiry = 5

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

U+0005

§

Acknowledge = 6

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

U+0006

§

Bell = 7

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

U+0007

§

Backspace = 8

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

U+0008

§

CharacterTabulation = 9

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

U+0009

§

LineFeed = 10

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

U+000A

§

LineTabulation = 11

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

U+000B

§

FormFeed = 12

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

U+000C

§

CarriageReturn = 13

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

U+000D

§

ShiftOut = 14

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

U+000E

§

ShiftIn = 15

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

U+000F

§

DataLinkEscape = 16

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

U+0010

§

DeviceControlOne = 17

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

U+0011

§

DeviceControlTwo = 18

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

U+0012

§

DeviceControlThree = 19

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

U+0013

§

DeviceControlFour = 20

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

U+0014

§

NegativeAcknowledge = 21

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

U+0015

§

SynchronousIdle = 22

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

U+0016

§

EndOfTransmissionBlock = 23

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

U+0017

§

Cancel = 24

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

U+0018

§

EndOfMedium = 25

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

U+0019

§

Substitute = 26

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

U+001A

§

Escape = 27

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

U+001B

§

InformationSeparatorFour = 28

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

U+001C

§

InformationSeparatorThree = 29

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

U+001D

§

InformationSeparatorTwo = 30

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

U+001E

§

InformationSeparatorOne = 31

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

U+001F

§

Space = 32

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

U+0020

§

ExclamationMark = 33

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

U+0021

§

QuotationMark = 34

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

U+0022

§

NumberSign = 35

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

U+0023

§

DollarSign = 36

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

U+0024

§

PercentSign = 37

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

U+0025

§

Ampersand = 38

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

U+0026

§

Apostrophe = 39

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

U+0027

§

LeftParenthesis = 40

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

U+0028

§

RightParenthesis = 41

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

U+0029

§

Asterisk = 42

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

U+002A

§

PlusSign = 43

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

U+002B

§

Comma = 44

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

U+002C

§

HyphenMinus = 45

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

U+002D

§

FullStop = 46

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

U+002E

§

Solidus = 47

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

U+002F

§

Digit0 = 48

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

U+0030

§

Digit1 = 49

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

U+0031

§

Digit2 = 50

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

U+0032

§

Digit3 = 51

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

U+0033

§

Digit4 = 52

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

U+0034

§

Digit5 = 53

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

U+0035

§

Digit6 = 54

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

U+0036

§

Digit7 = 55

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

U+0037

§

Digit8 = 56

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

U+0038

§

Digit9 = 57

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

U+0039

§

Colon = 58

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

U+003A

§

Semicolon = 59

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

U+003B

§

LessThanSign = 60

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

U+003C

§

EqualsSign = 61

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

U+003D

§

GreaterThanSign = 62

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

U+003E

§

QuestionMark = 63

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

U+003F

§

CommercialAt = 64

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

U+0040

§

CapitalA = 65

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

U+0041

§

CapitalB = 66

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

U+0042

§

CapitalC = 67

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

U+0043

§

CapitalD = 68

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

U+0044

§

CapitalE = 69

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

U+0045

§

CapitalF = 70

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

U+0046

§

CapitalG = 71

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

U+0047

§

CapitalH = 72

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

U+0048

§

CapitalI = 73

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

U+0049

§

CapitalJ = 74

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

U+004A

§

CapitalK = 75

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

U+004B

§

CapitalL = 76

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

U+004C

§

CapitalM = 77

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

U+004D

§

CapitalN = 78

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

U+004E

§

CapitalO = 79

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

U+004F

§

CapitalP = 80

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

U+0050

§

CapitalQ = 81

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

U+0051

§

CapitalR = 82

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

U+0052

§

CapitalS = 83

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

U+0053

§

CapitalT = 84

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

U+0054

§

CapitalU = 85

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

U+0055

§

CapitalV = 86

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

U+0056

§

CapitalW = 87

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

U+0057

§

CapitalX = 88

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

U+0058

§

CapitalY = 89

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

U+0059

§

CapitalZ = 90

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

U+005A

§

LeftSquareBracket = 91

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

U+005B

§

ReverseSolidus = 92

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

U+005C

§

RightSquareBracket = 93

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

U+005D

§

CircumflexAccent = 94

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

U+005E

§

LowLine = 95

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

U+005F

§

GraveAccent = 96

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

U+0060

§

SmallA = 97

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

U+0061

§

SmallB = 98

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

U+0062

§

SmallC = 99

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

U+0063

§

SmallD = 100

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

U+0064

§

SmallE = 101

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

U+0065

§

SmallF = 102

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

U+0066

§

SmallG = 103

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

U+0067

§

SmallH = 104

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

U+0068

§

SmallI = 105

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

U+0069

§

SmallJ = 106

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

U+006A

§

SmallK = 107

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

U+006B

§

SmallL = 108

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

U+006C

§

SmallM = 109

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

U+006D

§

SmallN = 110

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

U+006E

§

SmallO = 111

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

U+006F

§

SmallP = 112

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

U+0070

§

SmallQ = 113

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

U+0071

§

SmallR = 114

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

U+0072

§

SmallS = 115

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

U+0073

§

SmallT = 116

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

U+0074

§

SmallU = 117

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

U+0075

§

SmallV = 118

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

U+0076

§

SmallW = 119

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

U+0077

§

SmallX = 120

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

U+0078

§

SmallY = 121

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

U+0079

§

SmallZ = 122

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

U+007A

§

LeftCurlyBracket = 123

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

U+007B

§

VerticalLine = 124

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

U+007C

§

RightCurlyBracket = 125

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

U+007D

§

Tilde = 126

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

U+007E

§

Delete = 127

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

U+007F

Implementations§

Source§

impl AsciiChar

Source

pub const MIN: AsciiChar = Self::Null

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

The character with the lowest ASCII code.

Source

pub const MAX: AsciiChar = Self::Delete

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

The character with the highest ASCII code.

Source

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

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

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

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

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

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

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

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

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 loose 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 to_u8(self) -> u8

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

Gets this ASCII character as a byte.

Source

pub const fn to_char(self) -> char

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

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)

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

Source

pub const fn to_uppercase(self) -> AsciiChar

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

Makes a copy of the value in its upper case equivalent.

Letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’.

To uppercase the value in-place, use make_uppercase.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let lowercase_a = ascii::Char::SmallA;

assert_eq!(
    ascii::Char::CapitalA,
    lowercase_a.to_uppercase(),
);
Source

pub const fn to_lowercase(self) -> AsciiChar

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

Makes a copy of the value in its lower case equivalent.

Letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’.

To lowercase the value in-place, use make_lowercase.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;

assert_eq!(
    ascii::Char::SmallA,
    uppercase_a.to_lowercase(),
);
Source

pub const fn eq_ignore_case(self, other: AsciiChar) -> bool

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

Checks that two values are a case-insensitive match.

This is equivalent to to_lowercase(a) == to_lowercase(b).

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let lowercase_a = ascii::Char::SmallA;
let uppercase_a = ascii::Char::CapitalA;

assert!(lowercase_a.eq_ignore_case(uppercase_a));
Source

pub const fn make_uppercase(&mut self)

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

Converts this value to its upper case equivalent in-place.

Letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’.

To return a new uppercased value without modifying the existing one, use to_uppercase.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let mut letter_a = ascii::Char::SmallA;

letter_a.make_uppercase();

assert_eq!(ascii::Char::CapitalA, letter_a);
Source

pub const fn make_lowercase(&mut self)

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

Converts this value to its lower case equivalent in-place.

Letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’.

To return a new lowercased value without modifying the existing one, use to_lowercase.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let mut letter_a = ascii::Char::CapitalA;

letter_a.make_lowercase();

assert_eq!(ascii::Char::SmallA, letter_a);
Source

pub const fn is_alphabetic(self) -> bool

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

Checks if the value is an alphabetic character:

  • 0x41 ‘A’ ..= 0x5A ‘Z’, or
  • 0x61 ‘a’ ..= 0x7A ‘z’.
§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(uppercase_a.is_alphabetic());
assert!(uppercase_g.is_alphabetic());
assert!(a.is_alphabetic());
assert!(g.is_alphabetic());
assert!(!zero.is_alphabetic());
assert!(!percent.is_alphabetic());
assert!(!space.is_alphabetic());
assert!(!lf.is_alphabetic());
assert!(!esc.is_alphabetic());
Source

pub const fn is_uppercase(self) -> bool

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

Checks if the value is an uppercase character: 0x41 ‘A’ ..= 0x5A ‘Z’.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(uppercase_a.is_uppercase());
assert!(uppercase_g.is_uppercase());
assert!(!a.is_uppercase());
assert!(!g.is_uppercase());
assert!(!zero.is_uppercase());
assert!(!percent.is_uppercase());
assert!(!space.is_uppercase());
assert!(!lf.is_uppercase());
assert!(!esc.is_uppercase());
Source

pub const fn is_lowercase(self) -> bool

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

Checks if the value is a lowercase character: 0x61 ‘a’ ..= 0x7A ‘z’.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(!uppercase_a.is_lowercase());
assert!(!uppercase_g.is_lowercase());
assert!(a.is_lowercase());
assert!(g.is_lowercase());
assert!(!zero.is_lowercase());
assert!(!percent.is_lowercase());
assert!(!space.is_lowercase());
assert!(!lf.is_lowercase());
assert!(!esc.is_lowercase());
Source

pub const fn is_alphanumeric(self) -> bool

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

Checks if the value is an alphanumeric character:

  • 0x41 ‘A’ ..= 0x5A ‘Z’, or
  • 0x61 ‘a’ ..= 0x7A ‘z’, or
  • 0x30 ‘0’ ..= 0x39 ‘9’.
§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(uppercase_a.is_alphanumeric());
assert!(uppercase_g.is_alphanumeric());
assert!(a.is_alphanumeric());
assert!(g.is_alphanumeric());
assert!(zero.is_alphanumeric());
assert!(!percent.is_alphanumeric());
assert!(!space.is_alphanumeric());
assert!(!lf.is_alphanumeric());
assert!(!esc.is_alphanumeric());
Source

pub const fn is_digit(self) -> bool

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

Checks if the value is a decimal digit: 0x30 ‘0’ ..= 0x39 ‘9’.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(!uppercase_a.is_digit());
assert!(!uppercase_g.is_digit());
assert!(!a.is_digit());
assert!(!g.is_digit());
assert!(zero.is_digit());
assert!(!percent.is_digit());
assert!(!space.is_digit());
assert!(!lf.is_digit());
assert!(!esc.is_digit());
Source

pub const fn is_octdigit(self) -> bool

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

Checks if the value is an octal digit: 0x30 ‘0’ ..= 0x37 ‘7’.

§Examples
#![feature(ascii_char, ascii_char_variants, is_ascii_octdigit)]

use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let a = ascii::Char::SmallA;
let zero = ascii::Char::Digit0;
let seven = ascii::Char::Digit7;
let eight = ascii::Char::Digit8;
let percent = ascii::Char::PercentSign;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(!uppercase_a.is_octdigit());
assert!(!a.is_octdigit());
assert!(zero.is_octdigit());
assert!(seven.is_octdigit());
assert!(!eight.is_octdigit());
assert!(!percent.is_octdigit());
assert!(!lf.is_octdigit());
assert!(!esc.is_octdigit());
Source

pub const fn is_hexdigit(self) -> bool

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

Checks if the value is a hexadecimal digit:

  • 0x30 ‘0’ ..= 0x39 ‘9’, or
  • 0x41 ‘A’ ..= 0x46 ‘F’, or
  • 0x61 ‘a’ ..= 0x66 ‘f’.
§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(uppercase_a.is_hexdigit());
assert!(!uppercase_g.is_hexdigit());
assert!(a.is_hexdigit());
assert!(!g.is_hexdigit());
assert!(zero.is_hexdigit());
assert!(!percent.is_hexdigit());
assert!(!space.is_hexdigit());
assert!(!lf.is_hexdigit());
assert!(!esc.is_hexdigit());
Source

pub const fn is_punctuation(self) -> bool

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

Checks if the value is a punctuation character:

  • 0x21 ..= 0x2F ! " # $ % & ' ( ) * + , - . /, or
  • 0x3A ..= 0x40 : ; < = > ? @, or
  • 0x5B ..= 0x60 [ \ ] ^ _ `, or
  • 0x7B ..= 0x7E { | } ~
§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(!uppercase_a.is_punctuation());
assert!(!uppercase_g.is_punctuation());
assert!(!a.is_punctuation());
assert!(!g.is_punctuation());
assert!(!zero.is_punctuation());
assert!(percent.is_punctuation());
assert!(!space.is_punctuation());
assert!(!lf.is_punctuation());
assert!(!esc.is_punctuation());
Source

pub const fn is_graphic(self) -> bool

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

Checks if the value is a graphic character: 0x21 ‘!’ ..= 0x7E ‘~’.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(uppercase_a.is_graphic());
assert!(uppercase_g.is_graphic());
assert!(a.is_graphic());
assert!(g.is_graphic());
assert!(zero.is_graphic());
assert!(percent.is_graphic());
assert!(!space.is_graphic());
assert!(!lf.is_graphic());
assert!(!esc.is_graphic());
Source

pub const fn is_whitespace(self) -> bool

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

Checks if the value is a whitespace character: 0x20 SPACE, 0x09 HORIZONTAL TAB, 0x0A LINE FEED, 0x0C FORM FEED, or 0x0D CARRIAGE RETURN.

Rust uses the WhatWG Infra Standard’s definition of ASCII whitespace. There are several other definitions in wide use. For instance, the POSIX locale includes 0x0B VERTICAL TAB as well as all the above characters, but—from the very same specification—the default rule for “field splitting” in the Bourne shell considers only SPACE, HORIZONTAL TAB, and LINE FEED as whitespace.

If you are writing a program that will process an existing file format, check what that format’s definition of whitespace is before using this function.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(!uppercase_a.is_whitespace());
assert!(!uppercase_g.is_whitespace());
assert!(!a.is_whitespace());
assert!(!g.is_whitespace());
assert!(!zero.is_whitespace());
assert!(!percent.is_whitespace());
assert!(space.is_whitespace());
assert!(lf.is_whitespace());
assert!(!esc.is_whitespace());
Source

pub const fn is_control(self) -> bool

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

Checks if the value is a control character: 0x00 NUL ..= 0x1F UNIT SEPARATOR, or 0x7F DELETE. Note that most whitespace characters are control characters, but SPACE is not.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let uppercase_a = ascii::Char::CapitalA;
let uppercase_g = ascii::Char::CapitalG;
let a = ascii::Char::SmallA;
let g = ascii::Char::SmallG;
let zero = ascii::Char::Digit0;
let percent = ascii::Char::PercentSign;
let space = ascii::Char::Space;
let lf = ascii::Char::LineFeed;
let esc = ascii::Char::Escape;

assert!(!uppercase_a.is_control());
assert!(!uppercase_g.is_control());
assert!(!a.is_control());
assert!(!g.is_control());
assert!(!zero.is_control());
assert!(!percent.is_control());
assert!(!space.is_control());
assert!(lf.is_control());
assert!(esc.is_control());
Source

pub fn escape_ascii(self) -> EscapeDefault

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

Returns an iterator that produces an escaped version of a character.

The behavior is identical to ascii::escape_default.

§Examples
#![feature(ascii_char, ascii_char_variants)]
use std::ascii;

let zero = ascii::Char::Digit0;
let tab = ascii::Char::CharacterTabulation;
let cr = ascii::Char::CarriageReturn;
let lf = ascii::Char::LineFeed;
let apostrophe = ascii::Char::Apostrophe;
let double_quote = ascii::Char::QuotationMark;
let backslash = ascii::Char::ReverseSolidus;

assert_eq!("0", zero.escape_ascii().to_string());
assert_eq!("\\t", tab.escape_ascii().to_string());
assert_eq!("\\r", cr.escape_ascii().to_string());
assert_eq!("\\n", lf.escape_ascii().to_string());
assert_eq!("\\'", apostrophe.escape_ascii().to_string());
assert_eq!("\\\"", double_quote.escape_ascii().to_string());
assert_eq!("\\\\", backslash.escape_ascii().to_string());

Trait Implementations§

Source§

impl Clone for AsciiChar

Source§

fn clone(&self) -> AsciiChar

Returns a duplicate 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<(), Error>

Formats the value using the given formatter. Read more
1.0.0 (const: unstable) · Source§

impl Default for AsciiChar

Source§

fn default() -> AsciiChar

Returns the default value of Null

Source§

impl Display for AsciiChar

Source§

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

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

impl From<AsciiChar> for char

Source§

fn from(chr: AsciiChar) -> char

Converts to this type from the input type.
Source§

impl From<AsciiChar> for u128

Source§

fn from(chr: AsciiChar) -> u128

Converts to this type from the input type.
Source§

impl From<AsciiChar> for u16

Source§

fn from(chr: AsciiChar) -> u16

Converts to this type from the input type.
Source§

impl From<AsciiChar> for u32

Source§

fn from(chr: AsciiChar) -> u32

Converts to this type from the input type.
Source§

impl From<AsciiChar> for u64

Source§

fn from(chr: AsciiChar) -> u64

Converts to this type from the input type.
Source§

impl From<AsciiChar> for u8

Source§

fn from(chr: AsciiChar) -> u8

Converts to this type from the input type.
Source§

impl Hash for AsciiChar

Source§

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

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for AsciiChar

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Step for AsciiChar

Source§

fn steps_between(_: &AsciiChar, _: &AsciiChar) -> (usize, Option<usize>)

🔬This is a nightly-only experimental API. (step_trait)
Returns the bounds on the number of successor steps required to get from start to end like Iterator::size_hint(). Read more
Source§

fn forward_checked(start: AsciiChar, count: usize) -> Option<AsciiChar>

🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the successor of self count times. Read more
Source§

fn backward_checked(start: AsciiChar, count: usize) -> Option<AsciiChar>

🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the predecessor of self count times. Read more
Source§

unsafe fn forward_unchecked(start: AsciiChar, count: usize) -> AsciiChar

🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the successor of self count times. Read more
Source§

unsafe fn backward_unchecked(start: AsciiChar, count: usize) -> AsciiChar

🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the predecessor of self count times. Read more
Source§

fn forward(start: Self, count: usize) -> Self

🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the successor of self count times. Read more
Source§

fn backward(start: Self, count: usize) -> Self

🔬This is a nightly-only experimental API. (step_trait)
Returns the value that would be obtained by taking the predecessor of self count times. Read more
Source§

impl Copy for AsciiChar

Source§

impl Eq for AsciiChar

Source§

impl StructuralPartialEq for AsciiChar

Source§

impl TrustedStep for AsciiChar

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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 T
where 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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

Source§

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.