Function std_unicode::char::from_digit1.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