use core::{
marker::Unpin,
mem,
pin::Pin,
};
use tap::pipe::Pipe;
use super::BitBox;
use crate::{
order::BitOrder,
ptr::BitSpan,
slice::BitSlice,
store::BitStore,
vec::BitVec,
};
impl<O, T> BitBox<O, T>
where
O: BitOrder,
T: BitStore,
{
#[inline(always)]
#[cfg(not(tarpaulin_include))]
#[deprecated = "Prefer `from_bitslice`"]
pub fn new(x: &BitSlice<O, T>) -> Self {
Self::from_bitslice(x)
}
#[inline]
#[cfg(not(tarpaulin_include))]
pub fn pin(x: &BitSlice<O, T>) -> Pin<Self>
where
O: Unpin,
T: Unpin,
{
x.pipe(Self::from_bitslice).pipe(Pin::new)
}
#[inline]
pub unsafe fn from_raw(raw: *mut BitSlice<O, T>) -> Self {
Self {
bitspan: BitSpan::from_bitslice_ptr_mut(raw),
}
}
#[inline(always)]
#[cfg(not(tarpaulin_include))]
pub fn into_raw(this: Self) -> *mut BitSlice<O, T> {
Self::leak(this)
}
#[inline]
pub fn leak<'a>(this: Self) -> &'a mut BitSlice<O, T>
where T: 'a {
let out = this.bitspan.to_bitslice_mut();
mem::forget(this);
out
}
#[doc(hidden)]
#[inline(always)]
#[cfg(not(tarpaulin_include))]
#[deprecated = "Prefer `into_bitvec`"]
pub fn into_vec(self) -> BitVec<O, T> {
self.into_bitvec()
}
}