Function std::char::encode_utf8_raw

source ·
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> &mut [u8] 
🔬This is a nightly-only experimental API. (char_internals)
Expand description

Encodes a raw u32 value as UTF-8 into the provided byte buffer, and then returns the subslice of the buffer that contains the encoded character.

Unlike char::encode_utf8, this method also handles codepoints in the surrogate range. (Creating a char in the surrogate range is UB.) The result is valid generalized UTF-8 but not valid UTF-8.

Panics

Panics if the buffer is not large enough. A buffer of length four is large enough to encode any char.