1use crate::{AsBytes, Borrow, Clear, Columnar, Container, FromBytes, HeapSize, Index, IndexMut, Len, Push, Ref};
10
11impl<T: Columnar> Columnar for Box<T> {
12 type Container = Boxed<T::Container>;
13 #[inline(always)] fn copy_from<'a>(&mut self, other: Ref<'a, Self>) { self.as_mut().copy_from(other.0); }
14 #[inline(always)] fn into_owned<'a>(other: Ref<'a, Self>) -> Self { T::into_owned(other.0).into() }
15}
16
17#[derive(Copy, Clone, Default)]
19pub struct Boxed<T>(pub T);
20
21impl<T> std::ops::Deref for Boxed<T> {
22 type Target = T;
23 #[inline(always)] fn deref(&self) -> &T { &self.0 }
24}
25impl<T> std::ops::DerefMut for Boxed<T> {
26 #[inline(always)] fn deref_mut(&mut self) -> &mut T { &mut self.0 }
27}
28impl<C: Borrow> Borrow for Boxed<C> {
29 type Ref<'a> = Boxed<C::Ref<'a>>;
30 type Borrowed<'a> = Boxed<C::Borrowed<'a>>;
31 #[inline(always)] fn borrow<'a>(&'a self) -> Self::Borrowed<'a> { Boxed(self.0.borrow()) }
32 #[inline(always)] fn reborrow<'b, 'a: 'b>(item: Self::Borrowed<'a>) -> Self::Borrowed<'b> where Self: 'a { Boxed(C::reborrow(item.0)) }
33 #[inline(always)] fn reborrow_ref<'b, 'a: 'b>(item: Self::Ref<'a>) -> Self::Ref<'b> where Self: 'a { Boxed(C::reborrow_ref(item.0)) }
34}
35impl<C: Container> Container for Boxed<C> {
36 #[inline(always)] fn extend_from_self(&mut self, other: Self::Borrowed<'_>, range: std::ops::Range<usize>) { self.0.extend_from_self(other.0, range) }
37 #[inline(always)] fn reserve_for<'a, I>(&mut self, selves: I) where Self: 'a, I: Iterator<Item = Self::Borrowed<'a>> + Clone { self.0.reserve_for(selves.map(|x| x.0)) }
38}
39impl<C: Len> Len for Boxed<C> {
40 #[inline(always)] fn len(&self) -> usize { self.0.len() }
41 #[inline(always)] fn is_empty(&self) -> bool { self.0.is_empty() }
42}
43impl<C: Clear> Clear for Boxed<C> {
44 #[inline(always)] fn clear(&mut self) { self.0.clear() }
45}
46impl<'a, T: ?Sized, C: Container + Push<&'a T>> Push<&'a Box<T>> for Boxed<C> {
47 #[inline(always)] fn push(&mut self, item: &'a Box<T>) { self.0.push(item.as_ref()) }
48 #[inline(always)] fn extend(&mut self, iter: impl IntoIterator<Item=&'a Box<T>>) {
49 self.0.extend(iter.into_iter().map(|x| x.as_ref()))
50 }
51}
52impl<'a, C: Container> Push<Boxed<C::Ref<'a>>> for Boxed<C> {
53 #[inline(always)] fn push(&mut self, item: Boxed<C::Ref<'_>>) { self.0.push(item.0) }
54 #[inline(always)] fn extend(&mut self, iter: impl IntoIterator<Item=Boxed<C::Ref<'a>>>) {
55 self.0.extend(iter.into_iter().map(|x| x.0))
56 }
57}
58impl<'a, C: AsBytes<'a>> AsBytes<'a> for Boxed<C> {
59 #[inline(always)] fn as_bytes(&self) -> impl Iterator<Item=(u64, &'a [u8])> { self.0.as_bytes() }
60}
61impl<'a, C: FromBytes<'a>> FromBytes<'a> for Boxed<C> {
62 #[inline(always)] fn from_bytes(bytes: &mut impl Iterator<Item=&'a [u8]>) -> Self { Self(C::from_bytes(bytes)) }
63}
64impl<C: Index> Index for Boxed<C> {
65 type Ref = Boxed<C::Ref>;
66 #[inline(always)] fn get(&self, index: usize) -> Self::Ref { Boxed(self.0.get(index)) }
67}
68impl<C: IndexMut> IndexMut for Boxed<C> {
69 type IndexMut<'a> = Boxed<C::IndexMut<'a>> where Self: 'a;
70 #[inline(always)] fn get_mut(&mut self, index: usize) -> Self::IndexMut<'_> { Boxed(self.0.get_mut(index)) }
71}
72impl<C: HeapSize> HeapSize for Boxed<C> {
73 #[inline(always)] fn heap_size(&self) -> (usize, usize) { self.0.heap_size() }
74}