pub struct RawBitVec { /* private fields */ }
Expand description
§RawBitVec
: “Raw Bitwise Vector”
A BitVec
where the bit-width and masking data (BitProto
) must be manually passed to every function that accesses
any element or reallocates the underlying memory.
§Safety
The BitProto
passed to the methods of any given instance of RawBitVec
MUST be exactly the same as the very first one
pased to ANY of its methods that require it. For example, if you create a new instance with RawBitVec::new()
,
no assumptions are made about the data within and any BitProto
is valid. However, if you then use RawBitVec::push(PROTO_3_BITS, 5)
,
you MUST pass PROTO_3_BITS
for every other method call on this specific instance that requires a BitProto
, for its entire lifetime.
§Pros
- Same stack-size as
Vec
(3 usize) - Allows for constant-propogation optimizations (IF
BitProto
supplied to its methods is a constant) - No mono-morphization (smaller binary)
- Can store
RawBitVec
’s in a homogenous collection (Array
,Vec
,HashMap
, etc.)
§Cons
- UNSAFE if the same
BitProto
isnt used for every method call on the same instance of aRawBitVec
- Clunky API (requires manually passing an extra variable and nearly all methods are unsafe)
- Cannot truly implement many traits because their signatures don’t allow for a
BitProto
to be passed- Simple psuedo-iterators are provided that do require the same
BitProto
to be passed
- Simple psuedo-iterators are provided that do require the same
Implementations§
Source§impl RawBitVec
impl RawBitVec
pub fn len(&self) -> usize
pub unsafe fn cap(&self, proto: BitProto) -> usize
pub unsafe fn free(&self, proto: BitProto) -> usize
pub fn new() -> Self
pub fn with_capacity(proto: BitProto, cap: usize) -> Self
pub unsafe fn grow_exact_for_additional_elements_if_needed( &mut self, proto: BitProto, extra_elements: usize, ) -> Result<(), String>
pub unsafe fn grow_exact_for_total_elements_if_needed( &mut self, proto: BitProto, total_elements: usize, ) -> Result<(), String>
pub unsafe fn grow_for_additional_elements_if_needed( &mut self, proto: BitProto, extra_elements: usize, ) -> Result<(), String>
pub unsafe fn grow_for_total_elements_if_needed( &mut self, proto: BitProto, total_elements: usize, ) -> Result<(), String>
pub fn clear(&mut self)
pub unsafe fn push(&mut self, proto: BitProto, val: usize) -> Result<(), String>
pub unsafe fn push_unchecked(&mut self, proto: BitProto, val: usize)
pub unsafe fn pop(&mut self, proto: BitProto) -> Result<usize, String>
pub unsafe fn pop_unchecked(&mut self, proto: BitProto) -> usize
pub unsafe fn insert( &mut self, proto: BitProto, idx: usize, val: usize, ) -> Result<(), String>
pub unsafe fn insert_unchecked( &mut self, proto: BitProto, idx: usize, val: usize, )
pub unsafe fn insert_bitvec( &mut self, proto: BitProto, insert_idx: usize, bitvec: Self, ) -> Result<(), String>
pub unsafe fn insert_bitvec_unchecked( &mut self, proto: BitProto, insert_idx: usize, bitvec: Self, )
pub unsafe fn insert_iter<II, TO, ESI>(
&mut self,
proto: BitProto,
insert_idx: usize,
source: II,
) -> Result<(), String>where
II: IntoIterator<Item = TO, IntoIter = ESI>,
TO: ToOwned<Owned = usize>,
ESI: ExactSizeIterator + Iterator<Item = TO>,
pub unsafe fn insert_iter_unchecked<II, TO, ESI>(
&mut self,
proto: BitProto,
insert_idx: usize,
source: II,
)where
II: IntoIterator<Item = TO, IntoIter = ESI>,
TO: ToOwned<Owned = usize>,
ESI: ExactSizeIterator + Iterator<Item = TO>,
pub unsafe fn remove( &mut self, proto: BitProto, idx: usize, ) -> Result<usize, String>
pub unsafe fn remove_unchecked(&mut self, proto: BitProto, idx: usize) -> usize
pub unsafe fn remove_range( &mut self, proto: BitProto, remove_range: Range<usize>, ) -> Result<Self, String>
pub unsafe fn remove_range_unchecked( &mut self, proto: BitProto, remove_range: Range<usize>, ) -> Self
pub unsafe fn trim_range( &mut self, proto: BitProto, trim_start: RangeFrom<usize>, ) -> Result<Self, String>
pub unsafe fn trim_range_unchecked( &mut self, proto: BitProto, trim_start: RangeFrom<usize>, ) -> Self
pub unsafe fn swap( &mut self, proto: BitProto, idx_a: usize, idx_b: usize, ) -> Result<(), String>
pub unsafe fn swap_unchecked( &mut self, proto: BitProto, idx_a: usize, idx_b: usize, )
pub unsafe fn swap_pop( &mut self, proto: BitProto, idx: usize, ) -> Result<usize, String>
pub unsafe fn swap_pop_unchecked( &mut self, proto: BitProto, idx: usize, ) -> usize
pub unsafe fn trim_excess_capacity( &mut self, proto: BitProto, target_extra_capacity: usize, ) -> Result<(), String>
pub unsafe fn append_bitvec( &mut self, proto: BitProto, bitvec: Self, ) -> Result<(), String>
pub unsafe fn append_bitvec_unchecked(&mut self, proto: BitProto, bitvec: Self)
pub unsafe fn append_iter<II, TO, ESI>(
&mut self,
proto: BitProto,
source: II,
) -> Result<(), String>where
II: IntoIterator<Item = TO, IntoIter = ESI>,
TO: ToOwned<Owned = usize>,
ESI: ExactSizeIterator + Iterator<Item = TO>,
pub unsafe fn append_iter_unchecked<II, TO, ESI>(
&mut self,
proto: BitProto,
source: II,
)where
II: IntoIterator<Item = TO, IntoIter = ESI>,
TO: ToOwned<Owned = usize>,
ESI: ExactSizeIterator + Iterator<Item = TO>,
pub unsafe fn get(&self, proto: BitProto, idx: usize) -> Result<usize, String>
pub unsafe fn get_unchecked(&self, proto: BitProto, idx: usize) -> usize
pub unsafe fn replace( &mut self, proto: BitProto, idx: usize, val: usize, ) -> Result<usize, String>
pub unsafe fn replace_unchecked( &mut self, proto: BitProto, idx: usize, val: usize, ) -> usize
pub unsafe fn set( &mut self, proto: BitProto, idx: usize, val: usize, ) -> Result<(), String>
pub unsafe fn set_unchecked(&mut self, proto: BitProto, idx: usize, val: usize)
pub fn discard_from_end(&mut self, count: usize)
pub fn drain<'vec>(&'vec mut self) -> RawBitVecDrain<'vec>
pub fn into_iter(self) -> RawBitVecIter
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RawBitVec
impl RefUnwindSafe for RawBitVec
impl !Send for RawBitVec
impl !Sync for RawBitVec
impl Unpin for RawBitVec
impl UnwindSafe for RawBitVec
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more