rune::alloc::str

Function from_boxed_utf8_unchecked

Source
pub unsafe fn from_boxed_utf8_unchecked<A>(v: Box<[u8], A>) -> Box<str, A>
where A: Allocator,
Expand description

Converts a boxed slice of bytes to a boxed string slice without checking that the string contains valid UTF-8.

§Examples

use rune::alloc::Box;
use rune::alloc::str;

let smile_utf8 = Box::try_from([226, 152, 186])?;
let smile = unsafe { str::from_boxed_utf8_unchecked(smile_utf8) };

assert_eq!("☺", &*smile);

§Safety

The provided buffer must be valid UTF-8.