use crate::alloc::{Allocator, Global};
use crate::borrow::TryToOwned;
use crate::boxed::Box;
use crate::error::Error;
use crate::string::String;
#[must_use]
#[inline]
pub unsafe fn from_boxed_utf8_unchecked<A: Allocator>(v: Box<[u8], A>) -> Box<str, A> {
let (ptr, alloc) = Box::into_raw_with_allocator(v);
unsafe { Box::from_raw_in(ptr as *mut str, alloc) }
}
#[must_use = "`self` will be dropped if the result is not used"]
#[inline]
pub fn into_string<A: Allocator>(this: Box<str, A>) -> String<A> {
let slice = Box::<[u8], A>::from(this);
let vec = crate::slice::into_vec(slice);
unsafe { String::<A>::from_utf8_unchecked(vec) }
}
impl TryToOwned for str {
type Owned = String<Global>;
#[inline]
fn try_to_owned(&self) -> Result<String<Global>, Error> {
Ok(unsafe { String::from_utf8_unchecked(self.as_bytes().try_to_owned()?) })
}
}