//! General trait implementations for bit-vectors. use alloc::{ borrow::{ Cow, ToOwned, }, vec::Vec, }; use core::{ borrow::{ Borrow, BorrowMut, }, cmp, convert::TryFrom, fmt::{ self, Debug, Display, Formatter, }, hash::{ Hash, Hasher, }, marker::Unpin, }; use super::BitVec; use crate::{ array::BitArray, boxed::BitBox, order::BitOrder, slice::BitSlice, store::BitStore, view::BitViewSized, }; #[cfg(not(tarpaulin_include))] impl Borrow> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn borrow(&self) -> &BitSlice { self.as_bitslice() } } #[cfg(not(tarpaulin_include))] impl BorrowMut> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn borrow_mut(&mut self) -> &mut BitSlice { self.as_mut_bitslice() } } #[cfg(not(tarpaulin_include))] impl Clone for BitVec where T: BitStore, O: BitOrder, { #[inline] fn clone(&self) -> Self { Self::from_bitslice(self.as_bitslice()) } } impl Eq for BitVec where T: BitStore, O: BitOrder, { } #[cfg(not(tarpaulin_include))] impl Ord for BitVec where T: BitStore, O: BitOrder, { #[inline] fn cmp(&self, other: &Self) -> cmp::Ordering { self.as_bitslice().cmp(other.as_bitslice()) } } #[cfg(not(tarpaulin_include))] impl PartialEq> for BitSlice where T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder, { #[inline] fn eq(&self, other: &BitVec) -> bool { self == other.as_bitslice() } } #[cfg(not(tarpaulin_include))] impl PartialEq> for &BitSlice where T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder, { #[inline] fn eq(&self, other: &BitVec) -> bool { *self == other.as_bitslice() } } #[cfg(not(tarpaulin_include))] impl PartialEq> for &mut BitSlice where T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder, { #[inline] fn eq(&self, other: &BitVec) -> bool { **self == other.as_bitslice() } } #[cfg(not(tarpaulin_include))] impl PartialEq for BitVec where T: BitStore, O: BitOrder, Rhs: ?Sized + PartialEq>, { #[inline] fn eq(&self, other: &Rhs) -> bool { other == self.as_bitslice() } } #[cfg(not(tarpaulin_include))] impl PartialOrd> for BitSlice where T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder, { #[inline] fn partial_cmp(&self, other: &BitVec) -> Option { self.partial_cmp(other.as_bitslice()) } } #[cfg(not(tarpaulin_include))] impl<'a, T1, T2, O1, O2> PartialOrd> for &'a BitSlice where T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder, { #[inline] fn partial_cmp(&self, other: &BitVec) -> Option { self.partial_cmp(other.as_bitslice()) } } #[cfg(not(tarpaulin_include))] impl<'a, T1, T2, O1, O2> PartialOrd> for &'a mut BitSlice where T1: BitStore, T2: BitStore, O1: BitOrder, O2: BitOrder, { #[inline] fn partial_cmp(&self, other: &BitVec) -> Option { self.partial_cmp(other.as_bitslice()) } } #[cfg(not(tarpaulin_include))] impl PartialOrd for BitVec where T: BitStore, O: BitOrder, Rhs: ?Sized + PartialOrd>, { #[inline] fn partial_cmp(&self, other: &Rhs) -> Option { other.partial_cmp(self.as_bitslice()) } } #[cfg(not(tarpaulin_include))] impl AsRef> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn as_ref(&self) -> &BitSlice { self.as_bitslice() } } #[cfg(not(tarpaulin_include))] impl AsMut> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn as_mut(&mut self) -> &mut BitSlice { self.as_mut_bitslice() } } #[cfg(not(tarpaulin_include))] impl AsRef> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn as_ref(&self) -> &Self { self } } #[cfg(not(tarpaulin_include))] impl AsMut> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn as_mut(&mut self) -> &mut Self { self } } #[cfg(not(tarpaulin_include))] impl From<&'_ BitSlice> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn from(slice: &BitSlice) -> Self { Self::from_bitslice(slice) } } #[cfg(not(tarpaulin_include))] impl From<&'_ mut BitSlice> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn from(slice: &mut BitSlice) -> Self { Self::from_bitslice(slice) } } #[cfg(not(tarpaulin_include))] impl From> for BitVec where O: BitOrder, A: BitViewSized, { #[inline] fn from(array: BitArray) -> Self { array.as_bitslice().to_owned() } } #[cfg(not(tarpaulin_include))] impl From> for BitVec where T: BitStore, O: BitOrder, { #[inline] fn from(boxed: BitBox) -> Self { boxed.into_bitvec() } } #[cfg(not(tarpaulin_include))] impl From> for Vec where T: BitStore, O: BitOrder, { #[inline] fn from(bv: BitVec) -> Self { bv.into_vec() } } #[cfg(not(tarpaulin_include))] impl<'a, T, O> From>> for BitVec where O: BitOrder, T: 'a + BitStore, { #[inline] fn from(cow: Cow<'a, BitSlice>) -> Self { cow.into_owned() } } #[cfg(not(tarpaulin_include))] impl TryFrom> for BitVec where T: BitStore, O: BitOrder, { type Error = Vec; #[inline] fn try_from(vec: Vec) -> Result { Self::try_from_vec(vec) } } #[cfg(not(tarpaulin_include))] impl Default for BitVec where T: BitStore, O: BitOrder, { #[inline] fn default() -> Self { Self::new() } } impl Debug for BitVec where T: BitStore, O: BitOrder, { #[inline] fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { self.as_bitspan().render(fmt, "Vec", &[( "capacity", &self.capacity() as &dyn Debug, )])?; fmt.write_str(" ")?; Display::fmt(self, fmt) } } easy_fmt! { impl Binary impl Display impl LowerHex impl Octal impl Pointer impl UpperHex for BitVec } #[cfg(not(tarpaulin_include))] impl Hash for BitVec where T: BitStore, O: BitOrder, { #[inline] fn hash(&self, state: &mut H) where H: Hasher { self.as_bitslice().hash(state) } } unsafe impl Send for BitVec where T: BitStore, O: BitOrder, { } unsafe impl Sync for BitVec where T: BitStore, O: BitOrder, { } impl Unpin for BitVec where T: BitStore, O: BitOrder, { }