Function std::char::from_u32 [] [src]

pub fn from_u32(i: u32) -> Option<char>
1.0.0

Converts a u32 to a char.

Note that all chars are valid u32s, and can be casted to one with as:

fn main() { let c = '💯'; let i = c as u32; assert_eq!(128175, i); }
let c = '💯';
let i = c as u32;

assert_eq!(128175, i);

However, the reverse is not true: not all valid u32s are valid chars. from_u32() will return None if the input is not a valid value for a char.

For an unsafe version of this function which ignores these checks, see from_u32_unchecked().

Examples

Basic usage:

fn main() { use std::char; let c = char::from_u32(0x2764); assert_eq!(Some('❤'), c); }
use std::char;

let c = char::from_u32(0x2764);

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

Returning None when the input is not a valid char:

fn main() { use std::char; let c = char::from_u32(0x110000); assert_eq!(None, c); }
use std::char;

let c = char::from_u32(0x110000);

assert_eq!(None, c);