# Primitive Type char 1.0.0 [−]

A character type.

The `char` type represents a single character. More specifically, since 'character' isn't a well-defined concept in Unicode, `char` is a 'Unicode scalar value', which is similar to, but not the same as, a 'Unicode code point'.

This documentation describes a number of methods and trait implementations on the `char` type. For technical reasons, there is additional, separate documentation in the `std::char` module as well.

# Representation

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

    let v = vec!['h', 'e', 'l', 'l', 'o'];

    // five elements times four bytes for each element
    assert_eq!(20, v.len() * std::mem::size_of::<char>());

    let s = String::from("hello");

    // five elements times one byte per element
    assert_eq!(5, s.len() * std::mem::size_of::<u8>());Run

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

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

    let mut chars = "é".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());Run

This means that the contents of the first string above will fit into a `char` while the contents of the second string will not. Trying to create a `char` literal with the contents of the second string gives an error:

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

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

    let s = String::from("love: ❤️");
    let v: Vec<char> = s.chars().collect();

    assert_eq!(12, s.len() * std::mem::size_of::<u8>());
    assert_eq!(32, v.len() * std::mem::size_of::<char>());Run

## Methods

### `impl char`
[src]

#### `pub fn is_digit(self, radix: u32) -> bool`
[src]

Checks if a `char` is a digit in the given radix.

A 'radix' here is sometimes also called a 'base'. A radix of two indicates a binary number, a radix of ten, decimal, and a radix of sixteen, hexadecimal, to give some common values. Arbitrary radices are supported.

Compared to `is_numeric()`, this function only recognizes the characters `0-9`, `a-z` and `A-Z`.

'Digit' is defined to be only the following characters:

- `0-9`
- `a-z`
- `A-Z`

For a more comprehensive understanding of 'digit', see `is_numeric`.

# Panics

Panics if given a radix larger than 36.

# Examples

Basic usage:

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

Passing a large radix, causing a panic:

    use std::thread;

    let result = thread::spawn(|| {
        // this panics
        '1'.is_digit(37);
    }).join();

    assert!(result.is_err());Run

#### `pub fn to_digit(self, radix: u32) -> Option<u32>`
[src]

Converts a `char` to a digit in the given radix.

A 'radix' here is sometimes also called a 'base'. A radix of two indicates a binary number, a radix of ten, decimal, and a radix of sixteen, hexadecimal, to give some common values. Arbitrary radices are supported.

'Digit' is defined to be only the following characters:

- `0-9`
- `a-z`
- `A-Z`

# Errors

Returns `None` if the `char` does not refer to a digit in the given radix.

# Panics

Panics if given a radix larger than 36.

# Examples

Basic usage:

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

Passing a non-digit results in failure:

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

Passing a large radix, causing a panic:

    use std::thread;

    let result = thread::spawn(|| {
        '1'.to_digit(37);
    }).join();

    assert!(result.is_err());Run

####
ⓘImportant traits for EscapeUnicode

### Important traits for EscapeUnicode

`impl Iterator for EscapeUnicode type Item = char;`
`pub fn escape_unicode(self) -> EscapeUnicode`
[src]

Returns an iterator that yields the hexadecimal Unicode escape of a character as `char`s.

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

# Examples

As an iterator:

    for c in '❤'.escape_unicode() {
        print!("{}", c);
    }
    println!();Run

Using `println!` directly:

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

Both are equivalent to:

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

Using `to_string`:

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

####
ⓘImportant traits for EscapeDebug

### Important traits for EscapeDebug

`impl Iterator for EscapeDebug type Item = char;`
`pub fn escape_debug(self) -> EscapeDebug`
1.20.0
[src]

Returns an iterator that yields the literal escape code of a character as `char`s.

This will escape the characters similar to the `Debug` implementations of `str` or `char`.

# Examples

As an iterator:

    for c in '\n'.escape_debug() {
        print!("{}", c);
    }
    println!();Run

Using `println!` directly:

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

Both are equivalent to:

    println!("\\n");Run

Using `to_string`:

    assert_eq!('\n'.escape_debug().to_string(), "\\n");Run

####
ⓘImportant traits for EscapeDefault

### Important traits for EscapeDefault

`impl Iterator for EscapeDefault type Item = char;`
`pub fn escape_default(self) -> EscapeDefault`
[src]

Returns an iterator that yields the literal escape code of a character as `char`s.

The default is chosen with a bias toward producing literals that are legal in a variety of languages, including C++11 and similar C-family languages. 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' range `0x20` .. `0x7e` inclusive is not escaped.
- All other characters are given hexadecimal Unicode escapes; see `escape_unicode`.

# Examples

As an iterator:

    for c in '"'.escape_default() {
        print!("{}", c);
    }
    println!();Run

Using `println!` directly:

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

Both are equivalent to:

    println!("\\\"");Run

Using `to_string`:

    assert_eq!('"'.escape_default().to_string(), "\\\"");Run

#### `pub fn len_utf8(self) -> usize`
[src]

Returns the number of bytes this `char` would need if encoded in UTF-8.

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

# Examples

Basic usage:

    let len = 'A'.len_utf8();
    assert_eq!(len, 1);

    let len = 'ß'.len_utf8();
    assert_eq!(len, 2);

    let len = 'ℝ'.len_utf8();
    assert_eq!(len, 3);

    let len = '💣'.len_utf8();
    assert_eq!(len, 4);Run

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

    // as chars
    let eastern = '東';
    let capitol = '京';

    // both can be represented as three bytes
    assert_eq!(3, eastern.len_utf8());
    assert_eq!(3, capitol.len_utf8());

    // as a &str, these two are encoded in UTF-8
    let tokyo = "東京";

    let len = eastern.len_utf8() + capitol.len_utf8();

    // we can see that they take six bytes total...
    assert_eq!(6, tokyo.len());

    // ... just like the &str
    assert_eq!(len, tokyo.len());Run

#### `pub fn len_utf16(self) -> usize`
[src]

Returns the number of 16-bit code units this `char` would need if encoded in UTF-16.

See the documentation for `len_utf8` for more explanation of this concept. This function is a mirror, but for UTF-16 instead of UTF-8.

# Examples

Basic usage:

    let n = 'ß'.len_utf16();
    assert_eq!(n, 1);

    let len = '💣'.len_utf16();
    assert_eq!(len, 2);Run

#### `pub fn encode_utf8(self, dst: &mut [u8]) -> &mut str`
1.15.0
[src]

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 any `char`.

# Examples

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

    let mut b = [0; 2];

    let result = 'ß'.encode_utf8(&mut b);

    assert_eq!(result, "ß");

    assert_eq!(result.len(), 2);Run

A buffer that's too small:

    use std::thread;

    let result = thread::spawn(|| {
        let mut b = [0; 1];

        // this panics
       'ß'.encode_utf8(&mut b);
    }).join();

    assert!(result.is_err());Run

####
ⓘImportant traits for &'a [u8]

### Important traits for &'a [u8]

`impl<'a> Read for &'a [u8]impl<'a> Write for &'a mut [u8]`
`pub fn encode_utf16(self, dst: &mut [u16]) -> &mut [u16]`
1.15.0
[src]

Encodes this character as UTF-16 into the provided `u16` 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 any `char`.

# Examples

In both of these examples, '𝕊' takes two `u16`s to encode.

    let mut b = [0; 2];

    let result = '𝕊'.encode_utf16(&mut b);

    assert_eq!(result.len(), 2);Run

A buffer that's too small:

    use std::thread;

    let result = thread::spawn(|| {
        let mut b = [0; 1];

        // this panics
        '𝕊'.encode_utf16(&mut b);
    }).join();

    assert!(result.is_err());Run

#### `pub fn is_alphabetic(self) -> bool`
[src]

Returns true if this `char` is an alphabetic code point, and false if not.

# Examples

Basic usage:

    assert!('a'.is_alphabetic());
    assert!('京'.is_alphabetic());

    let c = '💝';
    // love is many things, but it is not alphabetic
    assert!(!c.is_alphabetic());Run

#### `pub fn is_xid_start(self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`rustc_private` #27812)

mainly needed for compiler internals

Returns true if this `char` satisfies the 'XID_Start' Unicode property, and false otherwise.

'XID_Start' is a Unicode Derived Property specified in UAX #31, mostly similar to `ID_Start` but modified for closure under `NFKx`.

#### `pub fn is_xid_continue(self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`rustc_private` #27812)

mainly needed for compiler internals

Returns true if this `char` satisfies the 'XID_Continue' Unicode property, and false otherwise.

'XID_Continue' is a Unicode Derived Property specified in UAX #31, mostly similar to 'ID_Continue' but modified for closure under NFKx.

#### `pub fn is_lowercase(self) -> bool`
[src]

Returns true if this `char` is lowercase, and false otherwise.

'Lowercase' is defined according to the terms of the Unicode Derived Core Property `Lowercase`.

# Examples

Basic usage:

    assert!('a'.is_lowercase());
    assert!('δ'.is_lowercase());
    assert!(!'A'.is_lowercase());
    assert!(!'Δ'.is_lowercase());

    // The various Chinese scripts do not have case, and so:
    assert!(!'中'.is_lowercase());Run

#### `pub fn is_uppercase(self) -> bool`
[src]

Returns true if this `char` is uppercase, and false otherwise.

'Uppercase' is defined according to the terms of the Unicode Derived Core Property `Uppercase`.

# Examples

Basic usage:

    assert!(!'a'.is_uppercase());
    assert!(!'δ'.is_uppercase());
    assert!('A'.is_uppercase());
    assert!('Δ'.is_uppercase());

    // The various Chinese scripts do not have case, and so:
    assert!(!'中'.is_uppercase());Run

#### `pub fn is_whitespace(self) -> bool`
[src]

Returns true if this `char` is whitespace, and false otherwise.

'Whitespace' is defined according to the terms of the Unicode Derived Core Property `White_Space`.

# Examples

Basic usage:

    assert!(' '.is_whitespace());

    // a non-breaking space
    assert!('\u{A0}'.is_whitespace());

    assert!(!'越'.is_whitespace());Run

#### `pub fn is_alphanumeric(self) -> bool`
[src]

Returns true if this `char` is alphanumeric, and false otherwise.

'Alphanumeric'-ness is defined in terms of the Unicode General Categories 'Nd', 'Nl', 'No' and the Derived Core Property 'Alphabetic'.

# Examples

Basic usage:

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

#### `pub fn is_control(self) -> bool`
[src]

Returns true if this `char` is a control code point, and false otherwise.

'Control code point' is defined in terms of the Unicode General Category `Cc`.

# Examples

Basic usage:

    // U+009C, STRING TERMINATOR
    assert!(''.is_control());
    assert!(!'q'.is_control());Run

#### `pub fn is_numeric(self) -> bool`
[src]

Returns true if this `char` is numeric, and false otherwise.

'Numeric'-ness is defined in terms of the Unicode General Categories 'Nd', 'Nl', 'No'.

# Examples

Basic usage:

    assert!('٣'.is_numeric());
    assert!('7'.is_numeric());
    assert!('৬'.is_numeric());
    assert!(!'K'.is_numeric());
    assert!(!'و'.is_numeric());
    assert!(!'藏'.is_numeric());
    assert!(!'¾'.is_numeric());
    assert!(!'①'.is_numeric());Run

####
ⓘImportant traits for ToLowercase

### Important traits for ToLowercase

`impl Iterator for ToLowercase type Item = char;`
`pub fn to_lowercase(self) -> ToLowercase`
[src]

Returns an iterator that yields the lowercase equivalent of a `char` as one or more `char`s.

If a character does not have a lowercase equivalent, the same character will be returned back by the iterator.

This performs complex unconditional mappings with no tailoring: it maps one Unicode character to its lowercase equivalent according to the Unicode database and the additional complex mappings `SpecialCasing.txt`. Conditional mappings (based on context or language) are not considered here.

For a full reference, see here.

# Examples

As an iterator:

    for c in 'İ'.to_lowercase() {
        print!("{}", c);
    }
    println!();Run

Using `println!` directly:

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

Both are equivalent to:

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

Using `to_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(), "山");Run

####
ⓘImportant traits for ToUppercase

### Important traits for ToUppercase

`impl Iterator for ToUppercase type Item = char;`
`pub fn to_uppercase(self) -> ToUppercase`
[src]

Returns an iterator that yields the uppercase equivalent of a `char` as one or more `char`s.

If a character does not have an uppercase equivalent, the same character will be returned back by the iterator.

This performs complex unconditional mappings with no tailoring: it maps one Unicode character to its uppercase equivalent according to the Unicode database and the additional complex mappings `SpecialCasing.txt`. Conditional mappings (based on context or language) are not considered here.

For a full reference, see here.

# Examples

As an iterator:

    for c in 'ß'.to_uppercase() {
        print!("{}", c);
    }
    println!();Run

Using `println!` directly:

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

Both are equivalent to:

    println!("SS");Run

Using `to_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(), "山");Run

# 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:

    let upper_i = 'i'.to_uppercase().to_string();Run

The value of `upper_i` here relies on the language of the text: if we're in `en-US`, it should be `"I"`, but if we're in `tr_TR`, it should be `"İ"`. `to_uppercase()` does not take this into account, and so:

    let upper_i = 'i'.to_uppercase().to_string();

    assert_eq!(upper_i, "I");Run

holds across languages.

#### `pub fn is_ascii(&self) -> bool`
1.23.0
[src]

Checks if the value is within the ASCII range.

# Examples

    let ascii = 'a';
    let non_ascii = '❤';

    assert!(ascii.is_ascii());
    assert!(!non_ascii.is_ascii());Run

#### `pub fn to_ascii_uppercase(&self) -> char`
1.23.0
[src]

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, use `make_ascii_uppercase`.

To uppercase ASCII characters in addition to non-ASCII characters, use `to_uppercase`.

# Examples

    let ascii = 'a';
    let non_ascii = '❤';

    assert_eq!('A', ascii.to_ascii_uppercase());
    assert_eq!('❤', non_ascii.to_ascii_uppercase());Run

#### `pub fn to_ascii_lowercase(&self) -> char`
1.23.0
[src]

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, use `make_ascii_lowercase`.

To lowercase ASCII characters in addition to non-ASCII characters, use `to_lowercase`.

# Examples

    let ascii = 'A';
    let non_ascii = '❤';

    assert_eq!('a', ascii.to_ascii_lowercase());
    assert_eq!('❤', non_ascii.to_ascii_lowercase());Run

#### `pub fn eq_ignore_ascii_case(&self, other: &char) -> bool`
1.23.0
[src]

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

Equivalent to `to_ascii_lowercase(a) == to_ascii_lowercase(b)`.

# Examples

    let upper_a = 'A';
    let lower_a = 'a';
    let lower_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));Run

#### `pub fn make_ascii_uppercase(&mut self)`
1.23.0
[src]

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, use `to_ascii_uppercase`.

# Examples

    let mut ascii = 'a';

    ascii.make_ascii_uppercase();

    assert_eq!('A', ascii);Run

#### `pub fn make_ascii_lowercase(&mut self)`
1.23.0
[src]

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, use `to_ascii_lowercase`.

# Examples

    let mut ascii = 'A';

    ascii.make_ascii_lowercase();

    assert_eq!('a', ascii);Run

#### `pub fn is_ascii_alphabetic(&self) -> bool`
1.24.0
[src]

Checks if the value is an ASCII alphabetic character:

- U+0041 'A' ... U+005A 'Z', or
- U+0061 'a' ... U+007A 'z'.

# Examples

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_uppercase(&self) -> bool`
1.24.0
[src]

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

# Examples

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_lowercase(&self) -> bool`
1.24.0
[src]

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

# Examples

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_alphanumeric(&self) -> bool`
1.24.0
[src]

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

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_digit(&self) -> bool`
1.24.0
[src]

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

# Examples

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_hexdigit(&self) -> bool`
1.24.0
[src]

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

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_punctuation(&self) -> bool`
1.24.0
[src]

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

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_graphic(&self) -> bool`
1.24.0
[src]

Checks if the value is an ASCII graphic character: U+0021 '@' ... U+007E '~'.

# Examples

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_whitespace(&self) -> bool`
1.24.0
[src]

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's definition of ASCII whitespace. There are several other definitions in wide use. For instance, the POSIX locale includes U+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 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_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

#### `pub fn is_ascii_control(&self) -> bool`
1.24.0
[src]

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 control characters, but SPACE is not.

# Examples

    #![feature(ascii_ctype)]

    let uppercase_a = 'A';
    let uppercase_g = 'G';
    let a = 'a';
    let g = 'g';
    let zero = '0';
    let percent = '%';
    let space = ' ';
    let lf = '\n';
    let esc: char = 0x1b_u8.into();

    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());Run

## Trait Implementations

### `impl FromStr for char`
1.20.0
[src]

#### `type Err = ParseCharError`

The associated error which can be returned from parsing.

#### `fn from_str(s: &str) -> Result<char, <char as FromStr>::Err>`
[src]

Parses a string `s` to return a value of this type. Read more

### `impl Debug for char`
[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result<(), Error>`
[src]

Formats the value using the given formatter. Read more

### `impl TryFrom<u32> for char`
[src]

#### `type Error = CharTryFromError`

🔬 This is a nightly-only experimental API. (`try_from` #33417)

The type returned in the event of a conversion error.

#### `fn try_from(i: u32) -> Result<char, <char as TryFrom<u32>>::Error>`
[src]

🔬 This is a nightly-only experimental API. (`try_from` #33417)

Performs the conversion.

### `impl Hash for char`
[src]

#### `fn hash<H>(&self, state: &mut H) where
H: Hasher,`
[src]

Feeds this value into the given [`Hasher`]. Read more

#### `fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,`
1.3.0
[src]

Feeds a slice of this type into the given [`Hasher`]. Read more

### `impl Default for char`
[src]

#### `fn default() -> char`
[src]

Returns the default value of `\x00`

### `impl PartialOrd<char> for char`
[src]

#### `fn partial_cmp(&self, other: &char) -> Option<Ordering>`
[src]

This method returns an ordering between `self` and `other` values if one exists. Read more

#### `fn lt(&self, other: &char) -> bool`
[src]

This method tests less than (for `self` and `other`) and is used by the `<` operator. Read more

#### `fn le(&self, other: &char) -> bool`
[src]

This method tests less than or equal to (for `self` and `other`) and is used by the `<=` operator. Read more

#### `fn ge(&self, other: &char) -> bool`
[src]

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

#### `fn gt(&self, other: &char) -> bool`
[src]

This method tests greater than (for `self` and `other`) and is used by the `>` operator. Read more

### `impl Ord for char`
[src]

#### `fn cmp(&self, other: &char) -> Ordering`
[src]

This method returns an `Ordering` between `self` and `other`. Read more

#### `fn max(self, other: Self) -> Self`
1.21.0
[src]

Compares and returns the maximum of two values. Read more

#### `fn min(self, other: Self) -> Self`
1.21.0
[src]

Compares and returns the minimum of two values. Read more

### `impl Display for char`
[src]

#### `fn fmt(&self, f: &mut Formatter) -> Result<(), Error>`
[src]

Formats the value using the given formatter. Read more

### `impl Eq for char`
[src]

### `impl PartialEq<char> for char`
[src]

#### `fn eq(&self, other: &char) -> bool`
[src]

This method tests for `self` and `other` values to be equal, and is used by `==`. Read more

#### `fn ne(&self, other: &char) -> bool`
[src]

This method tests for `!=`.

### `impl From<u8> for char`
1.13.0
[src]

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

Unicode is designed such that this effectively decodes bytes with 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 is also different from Windows-1252 a.k.a. code page 1252, which is a superset ISO/IEC 8859-1 that assigns some (not all!) blanks to punctuation and various Latin characters.

To confuse things further, on the Web `ascii`, `iso-8859-1`, and `windows-1252` are all aliases for a superset of Windows-1252 that fills the remaining blanks with corresponding C0 and C1 control codes.

#### `fn from(i: u8) -> char`
[src]

Performs the conversion.

### `impl<'a> Pattern<'a> for char`
[src]

Searches for chars that are equal to a given char

#### `type Searcher = CharSearcher<'a>`

🔬 This is a nightly-only experimental API. (`pattern` #27721)

API not fully fleshed out and ready to be stabilized

Associated searcher for this pattern

#### `fn into_searcher(self, haystack: &'a str) -> <char as Pattern<'a>>::Searcher`
[src]

🔬 This is a nightly-only experimental API. (`pattern` #27721)

API not fully fleshed out and ready to be stabilized

Constructs the associated searcher from `self` and the `haystack` to search in. Read more

#### `fn is_contained_in(self, haystack: &'a str) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`pattern` #27721)

API not fully fleshed out and ready to be stabilized

Checks whether the pattern matches anywhere in the haystack

#### `fn is_prefix_of(self, haystack: &'a str) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`pattern` #27721)

API not fully fleshed out and ready to be stabilized

Checks whether the pattern matches at the front of the haystack

#### `fn is_suffix_of(self, haystack: &'a str) -> bool where
<char as Pattern<'a>>::Searcher: ReverseSearcher<'a>,`
[src]

🔬 This is a nightly-only experimental API. (`pattern` #27721)

API not fully fleshed out and ready to be stabilized

Checks whether the pattern matches at the back of the haystack

### `impl AsciiExt for char`
[src]

#### `type Owned = char`

Container type for copied ASCII characters.

#### `fn is_ascii(&self) -> bool`
[src]

Checks if the value is within the ASCII range. Read more

#### `fn to_ascii_uppercase(&self) -> Self::Owned`
[src]

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

#### `fn to_ascii_lowercase(&self) -> Self::Owned`
[src]

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

#### `fn eq_ignore_ascii_case(&self, o: &Self) -> bool`
[src]

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

#### `fn make_ascii_uppercase(&mut self)`
[src]

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

#### `fn make_ascii_lowercase(&mut self)`
[src]

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

#### `fn is_ascii_alphabetic(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII alphabetic character: U+0041 'A' ... U+005A 'Z' or U+0061 'a' ... U+007A 'z'. For strings, true if all characters in the string are ASCII alphabetic. Read more

#### `fn is_ascii_uppercase(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII uppercase character: U+0041 'A' ... U+005A 'Z'. For strings, true if all characters in the string are ASCII uppercase. Read more

#### `fn is_ascii_lowercase(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII lowercase character: U+0061 'a' ... U+007A 'z'. For strings, true if all characters in the string are ASCII lowercase. Read more

#### `fn is_ascii_alphanumeric(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII alphanumeric character: U+0041 'A' ... U+005A 'Z', U+0061 'a' ... U+007A 'z', or U+0030 '0' ... U+0039 '9'. For strings, true if all characters in the string are ASCII alphanumeric. Read more

#### `fn is_ascii_digit(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII decimal digit: U+0030 '0' ... U+0039 '9'. For strings, true if all characters in the string are ASCII digits. Read more

#### `fn is_ascii_hexdigit(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII hexadecimal digit: U+0030 '0' ... U+0039 '9', U+0041 'A' ... U+0046 'F', or U+0061 'a' ... U+0066 'f'. For strings, true if all characters in the string are ASCII hex digits. Read more

#### `fn is_ascii_punctuation(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII punctuation character: Read more

#### `fn is_ascii_graphic(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

Checks if the value is an ASCII graphic character: U+0021 '@' ... U+007E '~'. For strings, true if all characters in the string are ASCII graphic characters. Read more

#### `fn is_ascii_whitespace(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

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. For strings, true if all characters in the string are ASCII whitespace. Read more

#### `fn is_ascii_control(&self) -> bool`
[src]

🔬 This is a nightly-only experimental API. (`ascii_ctype` #39658)

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 control characters, but SPACE is not. Read more

# Help

## Keyboard Shortcuts

`?`
  Show this help dialog
`S`
  Focus the search field
`↑`
  Move up in search results
`↓`
  Move down in search results
`↹`
  Switch tab
`⏎`
  Go to active search result
`+`
  Expand all sections
`-`
  Collapse all sections

## Search Tricks

Prefix searches with a type followed by a colon (e.g. `fn:`) to restrict the search to a given type.

Accepted types are: `fn`, `mod`, `struct`, `enum`, `trait`, `type`, `macro`, and `const`.

Search functions by type signature (e.g. `vec -> usize` or `* -> vec`)