pub unsafe fn from_boxed_utf8_unchecked(v: Box<[u8]>) -> Box<str>ⓘNotable traits for Box<I, A>impl<I: Iterator + ?Sized, A: Allocator> Iterator for Box<I, A> type Item = I::Item;impl<F: ?Sized + Future + Unpin, A: Allocator> Future for Box<F, A> where A: 'static, type Output = F::Output;
impl<I: Iterator + ?Sized, A: Allocator> Iterator for Box<I, A> type Item = I::Item;impl<F: ?Sized + Future + Unpin, A: Allocator> Future for Box<F, A> where A: 'static, type Output = F::Output;
将字节的 boxed 切片转换为 boxed 字符串切片,而无需检查该字符串是否包含有效的 UTF-8。
基本用法:
let smile_utf8 = Box::new([226, 152, 186]); let smile = unsafe { std::str::from_boxed_utf8_unchecked(smile_utf8) }; assert_eq!("☺", &*smile);