std_unicode::char::from_digit - Rust
Description: API documentation for the Rust `from_digit` fn in crate `std_unicode`.
Keywords: rust, rustlang, rust-lang, from_digit

# Function std_unicode::char::from_digit 1.0.0 [−] [src]

    pub fn from_digit(num: u32, radix: u32) -> Option<char>

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

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.

`from_digit()` will return `None` if the input is not a digit in the given radix.

# Panics

Panics if given a radix larger than 36.

# Examples

Basic usage:

    use std::char;

    let c = char::from_digit(4, 10);

    assert_eq!(Some('4'), c);

    // Decimal 11 is a single digit in base 16
    let c = char::from_digit(11, 16);

    assert_eq!(Some('b'), c);Run

Returning `None` when the input is not a digit:

    use std::char;

    let c = char::from_digit(20, 10);

    assert_eq!(None, c);Run

Passing a large radix, causing a panic:

    use std::thread;
    use std::char;

    let result = thread::spawn(|| {
        // this panics
        let c = char::from_digit(1, 37);
    }).join();

    assert!(result.is_err());Run

# 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
+ / -
  Collapse/expand 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`)