use super::*;
use std::borrow::Borrow;
use std::mem::ManuallyDrop;
use std::ptr;
pub unsafe trait IntoOwned {
type Owned : Borrow<Self> + Take<Self>;
unsafe fn into_owned_unchecked(this: &mut ManuallyDrop<Self>) -> Self::Owned;
}
unsafe impl<T> IntoOwned for T {
type Owned = T;
unsafe fn into_owned_unchecked(this: &mut ManuallyDrop<Self>) -> Self::Owned {
(this as *const _ as *const Self).read()
}
}
unsafe impl<T> IntoOwned for [T] {
type Owned = Vec<T>;
unsafe fn into_owned_unchecked(this: &mut ManuallyDrop<[T]>) -> Self::Owned {
let len = this.len();
let mut r = Vec::<T>::with_capacity(len);
ptr::copy_nonoverlapping(this.as_ptr(), r.as_mut_ptr(), len);
r.set_len(len);
r
}
}
#[cfg(test)]
mod tests {
}