Movatterモバイル変換


[0]ホーム

URL:


char

Primitive Typechar 

1.0.0
Expand description

A character type.

Thechar type represents a single character. More specifically, since‘character’ isn’t a well-defined concept in Unicode,char is a ‘Unicodescalar value’.

This documentation describes a number of methods and trait implementations on thechar type. For technical reasons, there is additional, separatedocumentation inthestd::char module as well.

§Validity and Layout

Achar is a ‘Unicode scalar value’, which is any ‘Unicode code point’other than asurrogate code point. This has a fixed numerical definition:code points are in the range 0 to 0x10FFFF, inclusive.Surrogate code points, used by UTF-16, are in the range 0xD800 to 0xDFFF.

Nochar may be constructed, whether as a literal or at runtime, that is not aUnicode scalar value. Violating this rule causes undefined behavior.

// Each of these is a compiler error['\u{D800}','\u{DFFF}','\u{110000}'];
// Panics; from_u32 returns None.char::from_u32(0xDE01).unwrap();
// Undefined behaviorlet _=unsafe{ char::from_u32_unchecked(0x110000) };

Unicode scalar values are also the exact set of values that may be encoded in UTF-8. Becausechar values are Unicode scalar values and functions may assumeincomingstr values arevalid UTF-8, it is safe to store anychar in astr or readany character from astr as achar.

The gap in validchar values is understood by the compiler, so in thebelow example the two ranges are understood to cover the whole range ofpossiblechar values and there is no error for anon-exhaustive match.

letc: char ='a';matchc {'\0'..='\u{D7FF}'=>false,'\u{E000}'..='\u{10FFFF}'=>true,};

All Unicode scalar values are validchar values, but not all of them represent a realcharacter. Many Unicode scalar values are not currently assigned to a character, but may be inthe future (“reserved”); some will never be a character (“noncharacters”); and some may be givendifferent meanings by different users (“private use”).

char is guaranteed to have the same size, alignment, and function call ABI asu32 on allplatforms.

usestd::alloc::Layout;assert_eq!(Layout::new::<char>(), Layout::new::<u32>());

§Representation

char is always four bytes in size. This is a different representation thana given character would have as part of aString. For example:

letv =vec!['h','e','l','l','o'];// five elements times four bytes for each elementassert_eq!(20, v.len() * size_of::<char>());lets = String::from("hello");// five elements times one byte per elementassert_eq!(5, s.len() * size_of::<u8>());

As always, remember that a human intuition for ‘character’ might not map toUnicode’s definitions. For example, despite looking similar, the ‘é’character is one Unicode code point while ‘é’ is two Unicode code points:

letmutchars ="é".chars();// U+00e9: 'latin small letter e with acute'assert_eq!(Some('\u{00e9}'), chars.next());assert_eq!(None, chars.next());letmutchars ="é".chars();// U+0065: 'latin small letter e'assert_eq!(Some('\u{0065}'), chars.next());// U+0301: 'combining acute accent'assert_eq!(Some('\u{0301}'), chars.next());assert_eq!(None, chars.next());

This means that the contents of the first string abovewill fit into achar while the contents of the second stringwill not. Trying to createachar literal with the contents of the second string gives an error:

error: character literal may only contain one codepoint: 'é'let c = 'é';        ^^^

Another implication of the 4-byte fixed size of achar is thatper-char processing can end up using a lot more memory:

lets = String::from("love: ❤️");letv: Vec<char> = s.chars().collect();assert_eq!(12, size_of_val(&s[..]));assert_eq!(32, size_of_val(&v[..]));

Implementations§

Source§

implchar

1.83.0 ·Source

pub constMIN:char = '\0'

The lowest valid code point achar can have,'\0'.

Unlike integer types,char actually has a gap in the middle,meaning that the range of possiblechars is smaller than youmight expect. Ranges ofchar will automatically hop this gapfor you:

letdist = u32::from(char::MAX) - u32::from(char::MIN);letsize = (char::MIN..=char::MAX).count()asu32;assert!(size < dist);

Despite this gap, theMIN andMAX values can be used as bounds forallchar values.

§Examples
letc: char = something_which_returns_char();assert!(char::MIN <= c);letvalue_at_min = u32::from(char::MIN);assert_eq!(char::from_u32(value_at_min),Some('\0'));
1.52.0 ·Source

pub constMAX:char = '\u{10FFFF}'

The highest valid code point achar can have,'\u{10FFFF}'.

Unlike integer types,char actually has a gap in the middle,meaning that the range of possiblechars is smaller than youmight expect. Ranges ofchar will automatically hop this gapfor you:

letdist = u32::from(char::MAX) - u32::from(char::MIN);letsize = (char::MIN..=char::MAX).count()asu32;assert!(size < dist);

Despite this gap, theMIN andMAX values can be used as bounds forallchar values.

§Examples
letc: char = something_which_returns_char();assert!(c <= char::MAX);letvalue_at_max = u32::from(char::MAX);assert_eq!(char::from_u32(value_at_max),Some('\u{10FFFF}'));assert_eq!(char::from_u32(value_at_max +1),None);
1.93.0 ·Source

pub constMAX_LEN_UTF8:usize = 4

The maximum number of bytes required toencode achar toUTF-8 encoding.

1.93.0 ·Source

pub constMAX_LEN_UTF16:usize = 2

The maximum number of two-byte units required toencode acharto UTF-16 encoding.

1.52.0 ·Source

pub constREPLACEMENT_CHARACTER:char = '\u{FFFD}'

U+FFFD REPLACEMENT CHARACTER (�) is used in Unicode to represent adecoding error.

It can occur, for example, when giving ill-formed UTF-8 bytes toString::from_utf8_lossy.

1.52.0 ·Source

pub constUNICODE_VERSION: (u8,u8,u8) = crate::unicode::UNICODE_VERSION

The version ofUnicode that the Unicode parts ofchar andstr methods are based on.

New versions of Unicode are released regularly and subsequently all methodsin the standard library depending on Unicode are updated. Therefore thebehavior of somechar andstr methods and the value of this constantchanges over time. This isnot considered to be a breaking change.

The version numbering scheme is explained inUnicode 11.0 or later, Section 3.1 Versions of the Unicode Standard.

1.52.0 ·Source

pub fndecode_utf16<I>(iter: I) ->DecodeUtf16<<I asIntoIterator>::IntoIter>
where I:IntoIterator<Item =u16>,

Creates an iterator over the native endian UTF-16 encoded code points initer,returning unpaired surrogates asErrs.

§Examples

Basic usage:

// 𝄞mus<invalid>ic<invalid>letv = [0xD834,0xDD1E,0x006d,0x0075,0x0073,0xDD1E,0x0069,0x0063,0xD834,];assert_eq!(    char::decode_utf16(v)        .map(|r| r.map_err(|e| e.unpaired_surrogate()))        .collect::<Vec<_>>(),vec![Ok('𝄞'),Ok('m'),Ok('u'),Ok('s'),Err(0xDD1E),Ok('i'),Ok('c'),Err(0xD834)    ]);

A lossy decoder can be obtained by replacingErr results with the replacement character:

// 𝄞mus<invalid>ic<invalid>letv = [0xD834,0xDD1E,0x006d,0x0075,0x0073,0xDD1E,0x0069,0x0063,0xD834,];assert_eq!(    char::decode_utf16(v)       .map(|r| r.unwrap_or(char::REPLACEMENT_CHARACTER))       .collect::<String>(),"𝄞mus�ic�");
1.52.0 (const: 1.67.0) ·Source

pub const fnfrom_u32(i:u32) ->Option<char>

Converts au32 to achar.

Note that allchars are validu32s, and can be cast to one withas:

letc ='💯';leti = casu32;assert_eq!(128175, i);

However, the reverse is not true: not all validu32s are validchars.from_u32() will returnNone if the input is not a valid valuefor achar.

For an unsafe version of this function which ignores these checks, seefrom_u32_unchecked.

§Examples

Basic usage:

letc = char::from_u32(0x2764);assert_eq!(Some('❤'), c);

ReturningNone when the input is not a validchar:

letc = char::from_u32(0x110000);assert_eq!(None, c);
1.52.0 (const: 1.81.0) ·Source

pub const unsafe fnfrom_u32_unchecked(i:u32) ->char

Converts au32 to achar, ignoring validity.

Note that allchars are validu32s, and can be cast to one withas:

letc ='💯';leti = casu32;assert_eq!(128175, i);

However, the reverse is not true: not all validu32s are validchars.from_u32_unchecked() will ignore this, and blindly cast tochar, possibly creating an invalid one.

§Safety

This function is unsafe, as it may construct invalidchar values.

For a safe version of this function, see thefrom_u32 function.

§Examples

Basic usage:

letc =unsafe{ char::from_u32_unchecked(0x2764) };assert_eq!('❤', c);
1.52.0 (const: 1.67.0) ·Source

pub const fnfrom_digit(num:u32, radix:u32) ->Option<char>

Converts a digit in the given radix to achar.

A ‘radix’ here is sometimes also called a ‘base’. A radix of twoindicates a binary number, a radix of ten, decimal, and a radix ofsixteen, hexadecimal, to give some common values. Arbitraryradices are supported.

from_digit() will returnNone if the input is not a digit inthe given radix.

§Panics

Panics if given a radix larger than 36.

§Examples

Basic usage:

letc = char::from_digit(4,10);assert_eq!(Some('4'), c);// Decimal 11 is a single digit in base 16letc = char::from_digit(11,16);assert_eq!(Some('b'), c);

ReturningNone when the input is not a digit:

letc = char::from_digit(20,10);assert_eq!(None, c);

Passing a large radix, causing a panic:

// this panicslet_c = char::from_digit(1,37);
1.0.0 (const: 1.87.0) ·Source

pub const fnis_digit(self, radix:u32) ->bool

Checks if achar is a digit in the given radix.

A ‘radix’ here is sometimes also called a ‘base’. A radix of twoindicates a binary number, a radix of ten, decimal, and a radix ofsixteen, hexadecimal, to give some common values. Arbitraryradices are supported.

Compared tois_numeric(), this function only recognizes the characters0-9,a-z andA-Z.

‘Digit’ is defined to be only the following characters:

  • 0-9
  • a-z
  • A-Z

For a more comprehensive understanding of ‘digit’, seeis_numeric().

§Panics

Panics if given a radix smaller than 2 or larger than 36.

§Examples

Basic usage:

assert!('1'.is_digit(10));assert!('f'.is_digit(16));assert!(!'f'.is_digit(10));

Passing a large radix, causing a panic:

// this panics'1'.is_digit(37);

Passing a small radix, causing a panic:

// this panics'1'.is_digit(1);
1.0.0 (const: 1.67.0) ·Source

pub const fnto_digit(self, radix:u32) ->Option<u32>

Converts achar to a digit in the given radix.

A ‘radix’ here is sometimes also called a ‘base’. A radix of twoindicates a binary number, a radix of ten, decimal, and a radix ofsixteen, hexadecimal, to give some common values. Arbitraryradices are supported.

‘Digit’ is defined to be only the following characters:

  • 0-9
  • a-z
  • A-Z
§Errors

ReturnsNone if thechar does not refer to a digit in the given radix.

§Panics

Panics if given a radix smaller than 2 or larger than 36.

§Examples

Basic usage:

assert_eq!('1'.to_digit(10),Some(1));assert_eq!('f'.to_digit(16),Some(15));

Passing a non-digit results in failure:

assert_eq!('f'.to_digit(10),None);assert_eq!('z'.to_digit(16),None);

Passing a large radix, causing a panic:

// this panicslet _='1'.to_digit(37);

Passing a small radix, causing a panic:

// this panicslet _='1'.to_digit(1);
1.0.0 ·Source

pub fnescape_unicode(self) ->EscapeUnicode

Returns an iterator that yields the hexadecimal Unicode escape of acharacter aschars.

This will escape characters with the Rust syntax of the form\u{NNNNNN} whereNNNNNN is a hexadecimal representation.

§Examples

As an iterator:

forcin'❤'.escape_unicode() {print!("{c}");}println!();

Usingprintln! directly:

println!("{}",'❤'.escape_unicode());

Both are equivalent to:

println!("\\u{{2764}}");

Usingto_string:

assert_eq!('❤'.escape_unicode().to_string(),"\\u{2764}");
1.20.0 ·Source

pub fnescape_debug(self) ->EscapeDebug

Returns an iterator that yields the literal escape code of a characteraschars.

This will escape the characters similar to theDebug implementationsofstr orchar.

§Examples

As an iterator:

forcin'\n'.escape_debug() {print!("{c}");}println!();

Usingprintln! directly:

println!("{}",'\n'.escape_debug());

Both are equivalent to:

println!("\\n");

Usingto_string:

assert_eq!('\n'.escape_debug().to_string(),"\\n");
1.0.0 ·Source

pub fnescape_default(self) ->EscapeDefault

Returns an iterator that yields the literal escape code of a characteraschars.

The default is chosen with a bias toward producing literals that arelegal in a variety of languages, including C++11 and similar C-familylanguages. The exact rules are:

  • Tab is escaped as\t.
  • Carriage return is escaped as\r.
  • Line feed is escaped as\n.
  • Single quote is escaped as\'.
  • Double quote is escaped as\".
  • Backslash is escaped as\\.
  • Any character in the ‘printable ASCII’ range0x20 ..0x7einclusive is not escaped.
  • All other characters are given hexadecimal Unicode escapes; seeescape_unicode.
§Examples

As an iterator:

forcin'"'.escape_default() {print!("{c}");}println!();

Usingprintln! directly:

println!("{}",'"'.escape_default());

Both are equivalent to:

println!("\\\"");

Usingto_string:

assert_eq!('"'.escape_default().to_string(),"\\\"");
1.0.0 (const: 1.52.0) ·Source

pub const fnlen_utf8(self) ->usize

Returns the number of bytes thischar would need if encoded in UTF-8.

That number of bytes is always between 1 and 4, inclusive.

§Examples

Basic usage:

letlen ='A'.len_utf8();assert_eq!(len,1);letlen ='ß'.len_utf8();assert_eq!(len,2);letlen ='ℝ'.len_utf8();assert_eq!(len,3);letlen ='💣'.len_utf8();assert_eq!(len,4);

The&str type guarantees that its contents are UTF-8, and so we can compare the length itwould take if each code point was represented as achar vs in the&str itself:

// as charsleteastern ='東';letcapital ='京';// both can be represented as three bytesassert_eq!(3, eastern.len_utf8());assert_eq!(3, capital.len_utf8());// as a &str, these two are encoded in UTF-8lettokyo ="東京";letlen = eastern.len_utf8() + capital.len_utf8();// we can see that they take six bytes total...assert_eq!(6, tokyo.len());// ... just like the &strassert_eq!(len, tokyo.len());
1.0.0 (const: 1.52.0) ·Source

pub const fnlen_utf16(self) ->usize

Returns the number of 16-bit code units thischar would need ifencoded in UTF-16.

That number of code units is always either 1 or 2, for unicode scalar values inthebasic multilingual plane orsupplementary planes respectively.

See the documentation forlen_utf8() for more explanation of thisconcept. This function is a mirror, but for UTF-16 instead of UTF-8.

§Examples

Basic usage:

letn ='ß'.len_utf16();assert_eq!(n,1);letlen ='💣'.len_utf16();assert_eq!(len,2);
1.15.0 (const: 1.83.0) ·Source

pub const fnencode_utf8(self, dst: &mut [u8]) -> &mutstr

Encodes this character as UTF-8 into the provided byte buffer,and then returns the subslice of the buffer that contains the encoded character.

§Panics

Panics if the buffer is not large enough.A buffer of length four is large enough to encode anychar.

§Examples

In both of these examples, ‘ß’ takes two bytes to encode.

letmutb = [0;2];letresult ='ß'.encode_utf8(&mutb);assert_eq!(result,"ß");assert_eq!(result.len(),2);

A buffer that’s too small:

letmutb = [0;1];// this panics'ß'.encode_utf8(&mutb);
1.15.0 (const: 1.84.0) ·Source

pub const fnencode_utf16(self, dst: &mut [u16]) -> &mut [u16]

Encodes this character as native endian UTF-16 into the providedu16 buffer,and then returns the subslice of the buffer that contains the encoded character.

§Panics

Panics if the buffer is not large enough.A buffer of length 2 is large enough to encode anychar.

§Examples

In both of these examples, ‘𝕊’ takes twou16s to encode.

letmutb = [0;2];letresult ='𝕊'.encode_utf16(&mutb);assert_eq!(result.len(),2);

A buffer that’s too small:

letmutb = [0;1];// this panics'𝕊'.encode_utf16(&mutb);
1.0.0 ·Source

pub fnis_alphabetic(self) ->bool

Returnstrue if thischar has theAlphabetic property.

Alphabetic is described in Chapter 4 (Character Properties) of theUnicode Standard andspecified in theUnicode Character DatabaseDerivedCoreProperties.txt.

§Examples

Basic usage:

assert!('a'.is_alphabetic());assert!('京'.is_alphabetic());letc ='💝';// love is many things, but it is not alphabeticassert!(!c.is_alphabetic());
1.0.0 (const: 1.84.0) ·Source

pub const fnis_lowercase(self) ->bool

Returnstrue if thischar has theLowercase property.

Lowercase is described in Chapter 4 (Character Properties) of theUnicode Standard andspecified in theUnicode Character DatabaseDerivedCoreProperties.txt.

§Examples

Basic usage:

assert!('a'.is_lowercase());assert!('δ'.is_lowercase());assert!(!'A'.is_lowercase());assert!(!'Δ'.is_lowercase());// The various Chinese scripts and punctuation do not have case, and so:assert!(!'中'.is_lowercase());assert!(!' '.is_lowercase());

In a const context:

constCAPITAL_DELTA_IS_LOWERCASE: bool ='Δ'.is_lowercase();assert!(!CAPITAL_DELTA_IS_LOWERCASE);
1.0.0 (const: 1.84.0) ·Source

pub const fnis_uppercase(self) ->bool

Returnstrue if thischar has theUppercase property.

Uppercase is described in Chapter 4 (Character Properties) of theUnicode Standard andspecified in theUnicode Character DatabaseDerivedCoreProperties.txt.

§Examples

Basic usage:

assert!(!'a'.is_uppercase());assert!(!'δ'.is_uppercase());assert!('A'.is_uppercase());assert!('Δ'.is_uppercase());// The various Chinese scripts and punctuation do not have case, and so:assert!(!'中'.is_uppercase());assert!(!' '.is_uppercase());

In a const context:

constCAPITAL_DELTA_IS_UPPERCASE: bool ='Δ'.is_uppercase();assert!(CAPITAL_DELTA_IS_UPPERCASE);
1.0.0 (const: 1.87.0) ·Source

pub const fnis_whitespace(self) ->bool

Returnstrue if thischar has theWhite_Space property.

White_Space is specified in theUnicode Character DatabasePropList.txt.

§Examples

Basic usage:

assert!(' '.is_whitespace());// line breakassert!('\n'.is_whitespace());// a non-breaking spaceassert!('\u{A0}'.is_whitespace());assert!(!'越'.is_whitespace());
1.0.0 ·Source

pub fnis_alphanumeric(self) ->bool

Returnstrue if thischar satisfies eitheris_alphabetic() oris_numeric().

§Examples

Basic usage:

assert!('٣'.is_alphanumeric());assert!('7'.is_alphanumeric());assert!('৬'.is_alphanumeric());assert!('¾'.is_alphanumeric());assert!('①'.is_alphanumeric());assert!('K'.is_alphanumeric());assert!('و'.is_alphanumeric());assert!('藏'.is_alphanumeric());
1.0.0 ·Source

pub fnis_control(self) ->bool

Returnstrue if thischar has the general category for control codes.

Control codes (code points with the general category ofCc) are described in Chapter 4(Character Properties) of theUnicode Standard and specified in theUnicode CharacterDatabaseUnicodeData.txt.

§Examples

Basic usage:

// U+009C, STRING TERMINATORassert!('œ'.is_control());assert!(!'q'.is_control());
1.0.0 ·Source

pub fnis_numeric(self) ->bool

Returnstrue if thischar has one of the general categories for numbers.

The general categories for numbers (Nd for decimal digits,Nl for letter-like numericcharacters, andNo for other numeric characters) are specified in theUnicode CharacterDatabaseUnicodeData.txt.

This method doesn’t cover everything that could be considered a number, e.g. ideographic numbers like ‘三’.If you want everything including characters with overlapping purposes then you might want to usea unicode or language-processing library that exposes the appropriate character properties insteadof looking at the unicode categories.

If you want to parse ASCII decimal digits (0-9) or ASCII base-N, useis_ascii_digit oris_digit instead.

§Examples

Basic usage:

assert!('٣'.is_numeric());assert!('7'.is_numeric());assert!('৬'.is_numeric());assert!('¾'.is_numeric());assert!('①'.is_numeric());assert!(!'K'.is_numeric());assert!(!'و'.is_numeric());assert!(!'藏'.is_numeric());assert!(!'三'.is_numeric());
1.0.0 ·Source

pub fnto_lowercase(self) ->ToLowercase

Returns an iterator that yields the lowercase mapping of thischar as one or morechars.

If thischar does not have a lowercase mapping, the iterator yields the samechar.

If thischar has a one-to-one lowercase mapping given by theUnicode CharacterDatabaseUnicodeData.txt, the iterator yields thatchar.

If thischar requires special considerations (e.g. multiplechars) the iterator yieldsthechar(s) given bySpecialCasing.txt.

This operation performs an unconditional mapping without tailoring. That is, the conversionis independent of context and language.

In theUnicode Standard, Chapter 4 (Character Properties) discusses case mapping ingeneral and Chapter 3 (Conformance) discusses the default algorithm for case conversion.

§Examples

As an iterator:

forcin'İ'.to_lowercase() {print!("{c}");}println!();

Usingprintln! directly:

println!("{}",'İ'.to_lowercase());

Both are equivalent to:

println!("i\u{307}");

Usingto_string:

assert_eq!('C'.to_lowercase().to_string(),"c");// Sometimes the result is more than one character:assert_eq!('İ'.to_lowercase().to_string(),"i\u{307}");// Characters that do not have both uppercase and lowercase// convert into themselves.assert_eq!('山'.to_lowercase().to_string(),"山");
1.0.0 ·Source

pub fnto_uppercase(self) ->ToUppercase

Returns an iterator that yields the uppercase mapping of thischar as one or morechars.

If thischar does not have an uppercase mapping, the iterator yields the samechar.

If thischar has a one-to-one uppercase mapping given by theUnicode CharacterDatabaseUnicodeData.txt, the iterator yields thatchar.

If thischar requires special considerations (e.g. multiplechars) the iterator yieldsthechar(s) given bySpecialCasing.txt.

This operation performs an unconditional mapping without tailoring. That is, the conversionis independent of context and language.

In theUnicode Standard, Chapter 4 (Character Properties) discusses case mapping ingeneral and Chapter 3 (Conformance) discusses the default algorithm for case conversion.

§Examples

As an iterator:

forcin'ß'.to_uppercase() {print!("{c}");}println!();

Usingprintln! directly:

println!("{}",'ß'.to_uppercase());

Both are equivalent to:

println!("SS");

Usingto_string:

assert_eq!('c'.to_uppercase().to_string(),"C");// Sometimes the result is more than one character:assert_eq!('ß'.to_uppercase().to_string(),"SS");// Characters that do not have both uppercase and lowercase// convert into themselves.assert_eq!('山'.to_uppercase().to_string(),"山");
§Note on locale

In Turkish, the equivalent of ‘i’ in Latin has five forms instead of two:

  • ‘Dotless’: I / ı, sometimes written ï
  • ‘Dotted’: İ / i

Note that the lowercase dotted ‘i’ is the same as the Latin. Therefore:

letupper_i ='i'.to_uppercase().to_string();

The value ofupper_i here relies on the language of the text: if we’reinen-US, it should be"I", but if we’re intr_TR, it shouldbe"İ".to_uppercase() does not take this into account, and so:

letupper_i ='i'.to_uppercase().to_string();assert_eq!(upper_i,"I");

holds across languages.

1.23.0 (const: 1.32.0) ·Source

pub const fnis_ascii(&self) ->bool

Checks if the value is within the ASCII range.

§Examples
letascii ='a';letnon_ascii ='❤';assert!(ascii.is_ascii());assert!(!non_ascii.is_ascii());
Source

pub const fnas_ascii(&self) ->Option<AsciiChar>

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

ReturnsSome if the value is within the ASCII range,orNone if it’s not.

This is preferred toSelf::is_ascii when you’re passing the valuealong to something else that can takeascii::Char rather thanneeding to check again for itself whether the value is in ASCII.

Source

pub const unsafe fnas_ascii_unchecked(&self) ->AsciiChar

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

Converts this char into anASCII character, withoutchecking whether it is valid.

§Safety

This char must be within the ASCII range, or else this is UB.

1.23.0 (const: 1.52.0) ·Source

pub const fnto_ascii_uppercase(&self) ->char

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

ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’,but non-ASCII letters are unchanged.

To uppercase the value in-place, usemake_ascii_uppercase().

To uppercase ASCII characters in addition to non-ASCII characters, useto_uppercase().

§Examples
letascii ='a';letnon_ascii ='❤';assert_eq!('A', ascii.to_ascii_uppercase());assert_eq!('❤', non_ascii.to_ascii_uppercase());
1.23.0 (const: 1.52.0) ·Source

pub const fnto_ascii_lowercase(&self) ->char

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

ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’,but non-ASCII letters are unchanged.

To lowercase the value in-place, usemake_ascii_lowercase().

To lowercase ASCII characters in addition to non-ASCII characters, useto_lowercase().

§Examples
letascii ='A';letnon_ascii ='❤';assert_eq!('a', ascii.to_ascii_lowercase());assert_eq!('❤', non_ascii.to_ascii_lowercase());
1.23.0 (const: 1.52.0) ·Source

pub const fneq_ignore_ascii_case(&self, other: &char) ->bool

Checks that two values are an ASCII case-insensitive match.

Equivalent toto_ascii_lowercase(a) ==to_ascii_lowercase(b).

§Examples
letupper_a ='A';letlower_a ='a';letlower_z ='z';assert!(upper_a.eq_ignore_ascii_case(&lower_a));assert!(upper_a.eq_ignore_ascii_case(&upper_a));assert!(!upper_a.eq_ignore_ascii_case(&lower_z));
1.23.0 (const: 1.84.0) ·Source

pub const fnmake_ascii_uppercase(&mut self)

Converts this type to its ASCII upper case equivalent in-place.

ASCII letters ‘a’ to ‘z’ are mapped to ‘A’ to ‘Z’,but non-ASCII letters are unchanged.

To return a new uppercased value without modifying the existing one, useto_ascii_uppercase().

§Examples
letmutascii ='a';ascii.make_ascii_uppercase();assert_eq!('A', ascii);
1.23.0 (const: 1.84.0) ·Source

pub const fnmake_ascii_lowercase(&mut self)

Converts this type to its ASCII lower case equivalent in-place.

ASCII letters ‘A’ to ‘Z’ are mapped to ‘a’ to ‘z’,but non-ASCII letters are unchanged.

To return a new lowercased value without modifying the existing one, useto_ascii_lowercase().

§Examples
letmutascii ='A';ascii.make_ascii_lowercase();assert_eq!('a', ascii);
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_alphabetic(&self) ->bool

Checks if the value is an ASCII alphabetic character:

  • U+0041 ‘A’ ..= U+005A ‘Z’, or
  • U+0061 ‘a’ ..= U+007A ‘z’.
§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(uppercase_a.is_ascii_alphabetic());assert!(uppercase_g.is_ascii_alphabetic());assert!(a.is_ascii_alphabetic());assert!(g.is_ascii_alphabetic());assert!(!zero.is_ascii_alphabetic());assert!(!percent.is_ascii_alphabetic());assert!(!space.is_ascii_alphabetic());assert!(!lf.is_ascii_alphabetic());assert!(!esc.is_ascii_alphabetic());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_uppercase(&self) ->bool

Checks if the value is an ASCII uppercase character:U+0041 ‘A’ ..= U+005A ‘Z’.

§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(uppercase_a.is_ascii_uppercase());assert!(uppercase_g.is_ascii_uppercase());assert!(!a.is_ascii_uppercase());assert!(!g.is_ascii_uppercase());assert!(!zero.is_ascii_uppercase());assert!(!percent.is_ascii_uppercase());assert!(!space.is_ascii_uppercase());assert!(!lf.is_ascii_uppercase());assert!(!esc.is_ascii_uppercase());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_lowercase(&self) ->bool

Checks if the value is an ASCII lowercase character:U+0061 ‘a’ ..= U+007A ‘z’.

§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(!uppercase_a.is_ascii_lowercase());assert!(!uppercase_g.is_ascii_lowercase());assert!(a.is_ascii_lowercase());assert!(g.is_ascii_lowercase());assert!(!zero.is_ascii_lowercase());assert!(!percent.is_ascii_lowercase());assert!(!space.is_ascii_lowercase());assert!(!lf.is_ascii_lowercase());assert!(!esc.is_ascii_lowercase());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_alphanumeric(&self) ->bool

Checks if the value is an ASCII alphanumeric character:

  • U+0041 ‘A’ ..= U+005A ‘Z’, or
  • U+0061 ‘a’ ..= U+007A ‘z’, or
  • U+0030 ‘0’ ..= U+0039 ‘9’.
§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(uppercase_a.is_ascii_alphanumeric());assert!(uppercase_g.is_ascii_alphanumeric());assert!(a.is_ascii_alphanumeric());assert!(g.is_ascii_alphanumeric());assert!(zero.is_ascii_alphanumeric());assert!(!percent.is_ascii_alphanumeric());assert!(!space.is_ascii_alphanumeric());assert!(!lf.is_ascii_alphanumeric());assert!(!esc.is_ascii_alphanumeric());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_digit(&self) ->bool

Checks if the value is an ASCII decimal digit:U+0030 ‘0’ ..= U+0039 ‘9’.

§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(!uppercase_a.is_ascii_digit());assert!(!uppercase_g.is_ascii_digit());assert!(!a.is_ascii_digit());assert!(!g.is_ascii_digit());assert!(zero.is_ascii_digit());assert!(!percent.is_ascii_digit());assert!(!space.is_ascii_digit());assert!(!lf.is_ascii_digit());assert!(!esc.is_ascii_digit());
Source

pub const fnis_ascii_octdigit(&self) ->bool

🔬This is a nightly-only experimental API. (is_ascii_octdigit #101288)

Checks if the value is an ASCII octal digit:U+0030 ‘0’ ..= U+0037 ‘7’.

§Examples
#![feature(is_ascii_octdigit)]letuppercase_a ='A';leta ='a';letzero ='0';letseven ='7';letnine ='9';letpercent ='%';letlf ='\n';assert!(!uppercase_a.is_ascii_octdigit());assert!(!a.is_ascii_octdigit());assert!(zero.is_ascii_octdigit());assert!(seven.is_ascii_octdigit());assert!(!nine.is_ascii_octdigit());assert!(!percent.is_ascii_octdigit());assert!(!lf.is_ascii_octdigit());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_hexdigit(&self) ->bool

Checks if the value is an ASCII hexadecimal digit:

  • U+0030 ‘0’ ..= U+0039 ‘9’, or
  • U+0041 ‘A’ ..= U+0046 ‘F’, or
  • U+0061 ‘a’ ..= U+0066 ‘f’.
§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(uppercase_a.is_ascii_hexdigit());assert!(!uppercase_g.is_ascii_hexdigit());assert!(a.is_ascii_hexdigit());assert!(!g.is_ascii_hexdigit());assert!(zero.is_ascii_hexdigit());assert!(!percent.is_ascii_hexdigit());assert!(!space.is_ascii_hexdigit());assert!(!lf.is_ascii_hexdigit());assert!(!esc.is_ascii_hexdigit());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_punctuation(&self) ->bool

Checks if the value is an ASCII punctuation character:

  • U+0021 ..= U+002F! " # $ % & ' ( ) * + , - . /, or
  • U+003A ..= U+0040: ; < = > ? @, or
  • U+005B ..= U+0060[ \ ] ^ _ `, or
  • U+007B ..= U+007E{ | } ~
§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(!uppercase_a.is_ascii_punctuation());assert!(!uppercase_g.is_ascii_punctuation());assert!(!a.is_ascii_punctuation());assert!(!g.is_ascii_punctuation());assert!(!zero.is_ascii_punctuation());assert!(percent.is_ascii_punctuation());assert!(!space.is_ascii_punctuation());assert!(!lf.is_ascii_punctuation());assert!(!esc.is_ascii_punctuation());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_graphic(&self) ->bool

Checks if the value is an ASCII graphic character:U+0021 ‘!’ ..= U+007E ‘~’.

§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(uppercase_a.is_ascii_graphic());assert!(uppercase_g.is_ascii_graphic());assert!(a.is_ascii_graphic());assert!(g.is_ascii_graphic());assert!(zero.is_ascii_graphic());assert!(percent.is_ascii_graphic());assert!(!space.is_ascii_graphic());assert!(!lf.is_ascii_graphic());assert!(!esc.is_ascii_graphic());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_whitespace(&self) ->bool

Checks if the value is an ASCII whitespace character:U+0020 SPACE, U+0009 HORIZONTAL TAB, U+000A LINE FEED,U+000C FORM FEED, or U+000D CARRIAGE RETURN.

Rust uses the WhatWG Infra Standard’sdefinition of ASCIIwhitespace. There are several other definitions inwide use. For instance,the POSIX locale includesU+000B 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 considersonlySPACE, HORIZONTAL TAB, and LINE FEED as whitespace.

If you are writing a program that will process an existingfile format, check what that format’s definition of whitespace isbefore using this function.

§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(!uppercase_a.is_ascii_whitespace());assert!(!uppercase_g.is_ascii_whitespace());assert!(!a.is_ascii_whitespace());assert!(!g.is_ascii_whitespace());assert!(!zero.is_ascii_whitespace());assert!(!percent.is_ascii_whitespace());assert!(space.is_ascii_whitespace());assert!(lf.is_ascii_whitespace());assert!(!esc.is_ascii_whitespace());
1.24.0 (const: 1.47.0) ·Source

pub const fnis_ascii_control(&self) ->bool

Checks if the value is an ASCII control character:U+0000 NUL ..= U+001F UNIT SEPARATOR, or U+007F DELETE.Note that most ASCII whitespace characters are controlcharacters, but SPACE is not.

§Examples
letuppercase_a ='A';letuppercase_g ='G';leta ='a';letg ='g';letzero ='0';letpercent ='%';letspace =' ';letlf ='\n';letesc ='\x1b';assert!(!uppercase_a.is_ascii_control());assert!(!uppercase_g.is_ascii_control());assert!(!a.is_ascii_control());assert!(!g.is_ascii_control());assert!(!zero.is_ascii_control());assert!(!percent.is_ascii_control());assert!(!space.is_ascii_control());assert!(lf.is_ascii_control());assert!(esc.is_ascii_control());

Trait Implementations§

1.0.0 ·Source§

implAsciiExt forchar

Source§

typeOwned =char

👎Deprecated since 1.26.0: use inherent methods instead
Container type for copied ASCII characters.
Source§

fnis_ascii(&self) ->bool

👎Deprecated since 1.26.0: use inherent methods instead
Checks if the value is within the ASCII range.Read more
Source§

fnto_ascii_uppercase(&self) -> Self::Owned

👎Deprecated since 1.26.0: use inherent methods instead
Makes a copy of the value in its ASCII upper case equivalent.Read more
Source§

fnto_ascii_lowercase(&self) -> Self::Owned

👎Deprecated since 1.26.0: use inherent methods instead
Makes a copy of the value in its ASCII lower case equivalent.Read more
Source§

fneq_ignore_ascii_case(&self, o: &Self) ->bool

👎Deprecated since 1.26.0: use inherent methods instead
Checks that two values are an ASCII case-insensitive match.Read more
Source§

fnmake_ascii_uppercase(&mut self)

👎Deprecated since 1.26.0: use inherent methods instead
Converts this type to its ASCII upper case equivalent in-place.Read more
Source§

fnmake_ascii_lowercase(&mut self)

👎Deprecated since 1.26.0: use inherent methods instead
Converts this type to its ASCII lower case equivalent in-place.Read more
1.0.0 (const:unstable) ·Source§

implClone forchar

Source§

fnclone(&self) ->char

Returns a duplicate of the value.Read more
1.0.0 ·Source§

fnclone_from(&mut self, source: &Self)

Performs copy-assignment fromsource.Read more
1.0.0 ·Source§

implDebug forchar

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result<(),Error>

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

implDefault forchar

Source§

fndefault() ->char

Returns the default value of\x00

1.0.0 ·Source§

implDisplay forchar

Source§

fnfmt(&self, f: &mutFormatter<'_>) ->Result<(),Error>

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

impl<'a>Extend<&'achar> forString

Source§

fnextend<I>(&mut self, iter: I)
where I:IntoIterator<Item = &'achar>,

Extends a collection with the contents of an iterator.Read more
Source§

fnextend_one(&mut self, _: &'achar)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
Source§

fnextend_reserve(&mut self, additional:usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements.Read more
1.0.0 ·Source§

implExtend<char> forString

Source§

fnextend<I>(&mut self, iter: I)
where I:IntoIterator<Item =char>,

Extends a collection with the contents of an iterator.Read more
Source§

fnextend_one(&mut self, c:char)

🔬This is a nightly-only experimental API. (extend_one #72631)
Extends a collection with exactly one element.
Source§

fnextend_reserve(&mut self, additional:usize)

🔬This is a nightly-only experimental API. (extend_one #72631)
Reserves capacity in a collection for the given number of additional elements.Read more
Source§

implFrom<AsciiChar> forchar

Source§

fnfrom(chr:AsciiChar) ->char

Converts to this type from the input type.
1.46.0 ·Source§

implFrom<char> forString

Source§

fnfrom(c:char) ->String

Allocates an ownedString from a single character.

§Example
letc: char ='a';lets: String = String::from(c);assert_eq!("a",&s[..]);
1.51.0 (const:unstable) ·Source§

implFrom<char> foru128

Source§

fnfrom(c:char) ->u128

Converts achar into au128.

§Examples
letc ='⚙';letu = u128::from(c);assert!(16== size_of_val(&u))
1.13.0 (const:unstable) ·Source§

implFrom<char> foru32

Source§

fnfrom(c:char) ->u32

Converts achar into au32.

§Examples
letc ='c';letu = u32::from(c);assert!(4== size_of_val(&u))
1.51.0 (const:unstable) ·Source§

implFrom<char> foru64

Source§

fnfrom(c:char) ->u64

Converts achar into au64.

§Examples
letc ='👤';letu = u64::from(c);assert!(8== size_of_val(&u))
1.13.0 (const:unstable) ·Source§

implFrom<u8> forchar

Maps a byte in 0x00..=0xFF to achar whose code point has the same value, in U+0000..=U+00FF.

Unicode is designed such that this effectively decodes byteswith the character encoding that IANA calls ISO-8859-1.This encoding is compatible with ASCII.

Note that this is different from ISO/IEC 8859-1 a.k.a. ISO 8859-1 (with one less hyphen),which leaves some “blanks”, byte values that are not assigned to any character.ISO-8859-1 (the IANA one) assigns them to the C0 and C1 control codes.

Note that this isalso different from Windows-1252 a.k.a. code page 1252,which is a superset ISO/IEC 8859-1 that assigns some (not all!) blanksto punctuation and various Latin characters.

To confuse things further,on the Webascii,iso-8859-1, andwindows-1252 are all aliasesfor a superset of Windows-1252 that fills the remaining blanks with correspondingC0 and C1 control codes.

Source§

fnfrom(i:u8) ->char

Converts au8 into achar.

§Examples
letu =32asu8;letc = char::from(u);assert!(4== size_of_val(&c))
1.80.0 ·Source§

impl<'a>FromIterator<&'achar> forBox<str>

Source§

fnfrom_iter<T>(iter: T) ->Box<str>
where T:IntoIterator<Item = &'achar>,

Creates a value from an iterator.Read more
1.17.0 ·Source§

impl<'a>FromIterator<&'achar> forString

Source§

fnfrom_iter<I>(iter: I) ->String
where I:IntoIterator<Item = &'achar>,

Creates a value from an iterator.Read more
1.80.0 ·Source§

implFromIterator<char> forBox<str>

Source§

fnfrom_iter<T>(iter: T) ->Box<str>
where T:IntoIterator<Item =char>,

Creates a value from an iterator.Read more
Source§

implFromIterator<char> forByteString

Source§

fnfrom_iter<T>(iter: T) ->ByteString
where T:IntoIterator<Item =char>,

Creates a value from an iterator.Read more
1.12.0 ·Source§

impl<'a>FromIterator<char> forCow<'a,str>

Source§

fnfrom_iter<I>(it: I) ->Cow<'a,str>
where I:IntoIterator<Item =char>,

Creates a value from an iterator.Read more
1.0.0 ·Source§

implFromIterator<char> forString

Source§

fnfrom_iter<I>(iter: I) ->String
where I:IntoIterator<Item =char>,

Creates a value from an iterator.Read more
1.20.0 ·Source§

implFromStr forchar

Source§

typeErr =ParseCharError

The associated error which can be returned from parsing.
Source§

fnfrom_str(s: &str) ->Result<char, <char asFromStr>::Err>

Parses a strings to return a value of this type.Read more
1.0.0 ·Source§

implHash forchar

Source§

fnhash<H>(&self, state:&mut H)
where H:Hasher,

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

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

Feeds a slice of this type into the givenHasher.Read more
1.0.0 (const:unstable) ·Source§

implOrd forchar

Source§

fncmp(&self, other: &char) ->Ordering

This method returns anOrdering betweenself andother.Read more
1.21.0 ·Source§

fnmax(self, other: Self) -> Self
where Self:Sized,

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

fnmin(self, other: Self) -> Self
where Self:Sized,

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

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

Restrict a value to a certain interval.Read more
1.0.0 (const:unstable) ·Source§

implPartialEq forchar

Source§

fneq(&self, other: &char) ->bool

Tests forself andother values to be equal, and is used by==.
Source§

fnne(&self, other: &char) ->bool

Tests for!=. The default implementation is almost always sufficient,and should not be overridden without very good reason.
1.0.0 (const:unstable) ·Source§

implPartialOrd forchar

Source§

fnpartial_cmp(&self, other: &char) ->Option<Ordering>

This method returns an ordering betweenself andother values if one exists.Read more
Source§

fnlt(&self, other: &char) ->bool

Tests less than (forself andother) and is used by the< operator.Read more
Source§

fnle(&self, other: &char) ->bool

Tests less than or equal to (forself andother) and is used by the<= operator.Read more
Source§

fngt(&self, other: &char) ->bool

Tests greater than (forself andother) and is used by the>operator.Read more
Source§

fnge(&self, other: &char) ->bool

Tests greater than or equal to (forself andother) and is used bythe>= operator.Read more
Source§

implPattern forchar

Searches for chars that are equal to a givenchar.

§Examples

assert_eq!("Hello world".find('o'),Some(4));
Source§

typeSearcher<'a> =CharSearcher<'a>

🔬This is a nightly-only experimental API. (pattern #27721)
Associated searcher for this pattern
Source§

fninto_searcher<'a>(self, haystack: &'astr) -> <char asPattern>::Searcher<'a>

🔬This is a nightly-only experimental API. (pattern #27721)
Constructs the associated searcher fromself and thehaystack to search in.
Source§

fnis_contained_in(self, haystack: &str) ->bool

🔬This is a nightly-only experimental API. (pattern #27721)
Checks whether the pattern matches anywhere in the haystack
Source§

fnis_prefix_of(self, haystack: &str) ->bool

🔬This is a nightly-only experimental API. (pattern #27721)
Checks whether the pattern matches at the front of the haystack
Source§

fnstrip_prefix_of(self, haystack: &str) ->Option<&str>

🔬This is a nightly-only experimental API. (pattern #27721)
Removes the pattern from the front of haystack, if it matches.
Source§

fnis_suffix_of<'a>(self, haystack: &'astr) ->bool
where <char asPattern>::Searcher<'a>:ReverseSearcher<'a>,

🔬This is a nightly-only experimental API. (pattern #27721)
Checks whether the pattern matches at the back of the haystack
Source§

fnstrip_suffix_of<'a>(self, haystack: &'astr) ->Option<&'astr>
where <char asPattern>::Searcher<'a>:ReverseSearcher<'a>,

🔬This is a nightly-only experimental API. (pattern #27721)
Removes the pattern from the back of haystack, if it matches.
Source§

fnas_utf8_pattern(&self) ->Option<Utf8Pattern<'_>>

🔬This is a nightly-only experimental API. (pattern #27721)
Returns the pattern as utf-8 bytes if possible.
Source§

implRangePattern forchar

Source§

constMIN:char = char::MIN

🔬This is a nightly-only experimental API. (pattern_type_range_trait #123646)
Trait version of the inherentMIN assoc const.
Source§

constMAX:char = char::MAX

🔬This is a nightly-only experimental API. (pattern_type_range_trait #123646)
Trait version of the inherentMIN assoc const.
Source§

fnsub_one(self) ->char

🔬This is a nightly-only experimental API. (pattern_type_range_trait #123646)
A compile-time helper to subtract 1 for exclusive ranges.
Source§

implStep forchar

Source§

fnsteps_between(_: &char, _: &char) -> (usize,Option<usize>)

🔬This is a nightly-only experimental API. (step_trait #42168)
Returns the bounds on the number ofsuccessor steps required to get fromstart toendlikeIterator::size_hint().Read more
Source§

fnforward_checked(start:char, count:usize) ->Option<char>

🔬This is a nightly-only experimental API. (step_trait #42168)
Returns the value that would be obtained by taking thesuccessorofselfcount times.Read more
Source§

fnbackward_checked(start:char, count:usize) ->Option<char>

🔬This is a nightly-only experimental API. (step_trait #42168)
Returns the value that would be obtained by taking thepredecessorofselfcount times.Read more
Source§

unsafe fnforward_unchecked(start:char, count:usize) ->char

🔬This is a nightly-only experimental API. (step_trait #42168)
Returns the value that would be obtained by taking thesuccessorofselfcount times.Read more
Source§

unsafe fnbackward_unchecked(start:char, count:usize) ->char

🔬This is a nightly-only experimental API. (step_trait #42168)
Returns the value that would be obtained by taking thepredecessorofselfcount times.Read more
Source§

fnforward(start: Self, count:usize) -> Self

🔬This is a nightly-only experimental API. (step_trait #42168)
Returns the value that would be obtained by taking thesuccessorofselfcount times.Read more
Source§

fnbackward(start: Self, count:usize) -> Self

🔬This is a nightly-only experimental API. (step_trait #42168)
Returns the value that would be obtained by taking thepredecessorofselfcount times.Read more
1.74.0 (const:unstable) ·Source§

implTryFrom<char> foru16

Maps achar with code point in U+0000..=U+FFFF to au16 in 0x0000..=0xFFFF with same value,failing if the code point is greater than U+FFFF.

This corresponds to the UCS-2 encoding, as specified in ISO/IEC 10646:2003.

Source§

fntry_from(c:char) ->Result<u16, <u16 asTryFrom<char>>::Error>

Tries to convert achar into au16.

§Examples
lettrans_rights ='⚧';// U+26A7letninjas ='🥷';// U+1F977assert_eq!(u16::try_from(trans_rights),Ok(0x26A7_u16));assert!(u16::try_from(ninjas).is_err());
Source§

typeError =TryFromCharError

The type returned in the event of a conversion error.
1.59.0 (const:unstable) ·Source§

implTryFrom<char> foru8

Maps achar with code point in U+0000..=U+00FF to a byte in 0x00..=0xFF with same value,failing if the code point is greater than U+00FF.

Seeimpl From<u8> for char for details on the encoding.

Source§

fntry_from(c:char) ->Result<u8, <u8 asTryFrom<char>>::Error>

Tries to convert achar into au8.

§Examples
leta ='ÿ';// U+00FFletb ='Ā';// U+0100assert_eq!(u8::try_from(a),Ok(0xFF_u8));assert!(u8::try_from(b).is_err());
Source§

typeError =TryFromCharError

The type returned in the event of a conversion error.
1.34.0 (const:unstable) ·Source§

implTryFrom<u32> forchar

Source§

typeError =CharTryFromError

The type returned in the event of a conversion error.
Source§

fntry_from(i:u32) ->Result<char, <char asTryFrom<u32>>::Error>

Performs the conversion.
Source§

implConstParamTy_ forchar

1.0.0 ·Source§

implCopy forchar

1.0.0 (const:unstable) ·Source§

implEq forchar

Source§

implStructuralPartialEq forchar

Source§

implTrustedStep forchar

Source§

implUseCloned forchar

Source§

implZeroablePrimitive forchar

Auto Trait Implementations§

§

implFreeze forchar

§

implRefUnwindSafe forchar

§

implSend forchar

§

implSync forchar

§

implUnpin forchar

§

implUnwindSafe forchar

Blanket Implementations§

Source§

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

Source§

fntype_id(&self) ->TypeId

Gets theTypeId ofself.Read more
Source§

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

Source§

fnborrow(&self) ->&T

Immutably borrows from an owned value.Read more
Source§

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

Source§

fnborrow_mut(&mut self) ->&mut T

Mutably borrows from an owned value.Read more
Source§

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

Source§

unsafe fnclone_to_uninit(&self, dest:*mutu8)

🔬This is a nightly-only experimental API. (clone_to_uninit #126799)
Performs copy-assignment fromself todest.Read more
Source§

impl<T>From<NonZero<T>> for T

Source§

fnfrom(nonzero:NonZero<T>) -> T

Converts to this type from the input type.
Source§

impl<T>From<T> for T

Source§

fnfrom(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fninto(self) -> U

CallsU::from(self).

That is, this conversion is whatever the implementation ofFrom<T> for U chooses to do.

Source§

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

Source§

typeOwned = T

The resulting type after obtaining ownership.
Source§

fnto_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning.Read more
Source§

fnclone_into(&self, target:&mut T)

Uses borrowed data to replace owned data, usually by cloning.Read more
Source§

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

Source§

fnto_string(&self) ->String

Converts the given value to aString.Read more
Source§

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

Source§

typeError =Infallible

The type returned in the event of a conversion error.
Source§

fntry_from(value: U) ->Result<T, <T asTryFrom<U>>::Error>

Performs the conversion.
Source§

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

Source§

typeError = <U asTryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fntry_into(self) ->Result<U, <U asTryFrom<T>>::Error>

Performs the conversion.

[8]ページ先頭

©2009-2026 Movatter.jp