Python has the unichr()
(or chr()
in Python 3) function that takes an integer and returns a character with the Unicode code point of that number. Does Rust have an equivalent function?
相关问题
- Share Arc between closures
- Function references: expected bound lifetime param
- Pattern matching on slices
- How can I iteratively call Sha256::digest, passing
- Destructure a vector into variables and give away
相关文章
- How can I convert a f64 to f32 and get the closest
- What is a good way of cleaning up after a unit tes
- How can I unpack (destructure) elements from a vec
- How to import macros in Rust?
- How to get struct field names in Rust? [duplicate]
- Confusion between [T] and &[T]
- How do I initialize an opaque C struct when using
- What's the most idiomatic way to test two Opti
Sure, though it is a built-in operator
as
:Note that
as
operator works only foru8
numbers, something else will cause a compilation error:If you need a string (to fully emulate the Python function), use
to_string()
:There is also the
char::from_u32
function:It returns an
Option<char>
because not every number is a valid Unicode code point - the only valid numbers are 0x0000 to 0xD7FF and from 0xE000 to 0x10FFFF. This function is applicable to a larger set of values thanas char
and can convert numbers larger than one byte, providing you access to the whole range of Unicode code points.I've compiled a set of examples on the Playground.