Skip to main content

BitBuf

Struct BitBuf 

Source
pub struct BitBuf<S> { /* private fields */ }
Expand description

The main structure

Keeps track of the data storage and a cursor for automatic operations

Implementations§

Source§

impl<S> BitBuf<S>

Source

pub const fn from(data: S) -> Self

Construct from provided data storage

Source

pub fn bytes(&self) -> &[u8]
where S: Storage,

Get the underlying bytes from the storage

Source

pub fn bytes_mut(&mut self) -> &mut [u8]
where S: StorageMut,

Get the underlying bytes from the storage

Source

pub fn pos(&self) -> usize

Get the internal cursor for automatic operations

The cursor may not be within storage bounds

Source

pub fn byte_pos(&self) -> usize

Get the byte-aligned position of the internal cursor for automatic operations

The cursor may not be within storage bounds

Source

pub fn advance(&mut self, bits: usize) -> &mut Self

Advance the internal cursor for automatic operations

This does not enforce that the cursor stay within storage bounds

Source

pub fn advance_bytes(&mut self, bytes: usize) -> &mut Self

Advance the internal cursor for automatic operations by a number of bytes

This does not enforce that the cursor stay within storage bounds

Source

pub fn seek(&mut self, offset: usize) -> &mut Self

Set the internal cursor for automatic operations

This does not enforce that the cursor stay within storage bounds

Source

pub fn seek_byte(&mut self, byte: usize) -> &mut Self

Set the internal cursor for automatic operations to a byte position

This sets the cursor to offset * 8 bits.

This does not enforce that the cursor stay within storage bounds

Source

pub fn is_aligned(&self) -> bool

Checks if the internal cursor for automatic operations is aligned on the start of a byte

This does not care whether the cursor is outside storage bounds

Source§

impl<S: Storage> BitBuf<S>

Source

pub unsafe fn read_u8_be_aligned_full_at_unchecked( &self, byte_offset: usize, ) -> u8

Read a BE-bit-order u8 from byte_offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn read_u8_be_aligned_full_unchecked(&mut self) -> u8

Read the next BE-bit-order u8 without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub unsafe fn read_u8_be_full_at_unchecked(&self, offset: usize) -> u8

Read a BE-bit-order u8 from offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn read_u8_be_full_unchecked(&mut self) -> u8

Read the next BE-bit-order u8 without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub fn try_read_u8_be_full_at(&self, offset: usize) -> Result<u8>

Read a BE-bit-order u8 from offset while performing bound checks

§Errors
Source

pub fn try_read_u8_be_full(&mut self) -> Result<u8>

Read the next BE-bit-order u8 while performing bound checks, advancing the internal cursor

§Errors
Source

pub fn read_u8_be_full_at(&self, offset: usize) -> u8

Read a BE-bit-order u8 from offset, panicking on out of bounds

§Panics
Source

pub fn read_u8_be_full(&mut self) -> u8

Read the next BE-bit-order u8, panicking on out of bounds, advancing the internal cursor

§Panics
Source

pub unsafe fn read_u16_be_aligned_full_at_unchecked( &self, byte_offset: usize, ) -> u16

Read a [BE-bit, BE-byte] order u16 from byte_offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn read_u16_be_aligned_full_unchecked(&mut self) -> u16

Read the next [BE-bit, BE-byte] order u16 without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub unsafe fn read_u16_be_full_at_unchecked(&self, offset: usize) -> u16

Read a [BE-bit, BE-byte] order u16 from offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn read_u16_be_full_unchecked(&mut self) -> u16

Read the next [BE-bit, BE-byte] order u16 without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub fn try_read_u16_be_full_at(&self, offset: usize) -> Result<u16>

Read a [BE-bit, BE-byte] order u16 from offset while performing bound checks

§Errors
Source

pub fn try_read_u16_be_full(&mut self) -> Result<u16>

Read the next [BE-bit, BE-byte] order u16 while performing bound checks, advancing the internal cursor

§Errors
Source

pub fn read_u16_be_full_at(&self, offset: usize) -> u16

Read a [BE-bit, BE-byte] order u16 from offset, panicking on out of bounds

§Panics
Source

pub fn read_u16_be_full(&mut self) -> u16

Read the next [BE-bit, BE-byte] order u16, panicking on out of bounds, advancing the internal cursor

§Panics
Source

pub unsafe fn read_u32_be_aligned_full_at_unchecked( &self, byte_offset: usize, ) -> u32

Read a u32 in [BE-bit, BE-byte] order at byte_offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn read_u32_be_aligned_full_unchecked(&mut self) -> u32

Read the next u32 in [BE-bit, BE-byte] order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub unsafe fn read_u32_be_full_at_unchecked(&self, offset: usize) -> u32

Read a u32 in [BE-bit, BE-byte] order from offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn read_u32_be_full_unchecked(&mut self) -> u32

Read the next u32 in [BE-bit, BE-byte] order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub fn try_read_u32_be_full_at(&self, offset: usize) -> Result<u32>

Read a [BE-bit, BE-byte] order u32 from offset while performing bound checks

§Errors
Source

pub fn try_read_u32_be_full(&mut self) -> Result<u32>

Read the next [BE-bit, BE-byte] order u32 while performing bound checks, advancing the internal cursor

§Errors
Source

pub fn read_u32_be_full_at(&self, offset: usize) -> u32

Read a [BE-bit, BE-byte] order u32 from offset, panicking on out of bounds

§Panics
Source

pub fn read_u32_be_full(&mut self) -> u32

Read the next [BE-bit, BE-byte] order u32, panicking on out of bounds, advancing the internal cursor

§Panics
Source§

impl<S: Storage> BitBuf<S>

Source

pub unsafe fn read_be_aligned_full_at_unchecked<T: Read>( &self, byte_offset: usize, ) -> T

Read a [BE-bit, BE-byte] order type T from byte_offset without performing bound checks

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub unsafe fn read_be_aligned_full_unchecked<T: Read>(&mut self) -> T

Read the next [BE-bit, BE-byte] order type T without performing bound checks, advancing the internal cursor

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub unsafe fn read_be_full_at_unchecked<T: Read>(&self, offset: usize) -> T

Read a [BE-bit, BE-byte] order type T from offset without performing bound checks

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub unsafe fn read_be_full_unchecked<T: Read>(&mut self) -> T

Read the next [BE-bit, BE-byte] order type T without performing bound checks, advancing the internal cursor

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub fn try_read_be_full_at<T: Read>(&self, offset: usize) -> Result<T>

Read a [BE-bit, BE-byte] order type T from offset while performing bound checks

§Errors

All semantics of the corresponding function for the type apply

Source

pub fn try_read_be_full<T: Read>(&mut self) -> Result<T>

Read the next [BE-bit, BE-byte] order type T while performing bound checks, advancing the internal cursor

§Errors

All semantics of the corresponding function for the type apply

Source

pub fn read_be_full_at<T: Read>(&self, offset: usize) -> T

Read a [BE-bit, BE-byte] order type T from offset, panicking on out of bounds

§Panics

All semantics of the corresponding function for the type apply

Source

pub fn read_be_full<T: Read>(&mut self) -> T

Read the next [BE-bit, BE-byte] order type T, panicking on out of bounds, advancing the internal cursor

§Panics

All semantics of the corresponding function for the type apply

Source§

impl<S: StorageMut> BitBuf<S>

Source

pub unsafe fn write_u8_be_aligned_full_at_unchecked( &mut self, byte_offset: usize, v: u8, ) -> &mut Self

Write a u8 in BE-bit-order at byte_offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn write_u8_be_aligned_full_unchecked(&mut self, v: u8) -> &mut Self

Write a u8 in BE-bit-order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub unsafe fn write_u8_be_full_at_unchecked( &mut self, offset: usize, v: u8, ) -> &mut Self

Write a u8 in BE-bit-order at offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn write_u8_be_full_unchecked(&mut self, v: u8) -> &mut Self

Write a u8 in BE-bit-order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub fn try_write_u8_be_full_at( &mut self, offset: usize, v: u8, ) -> Result<&mut Self>

Write a BE-bit-order u8 at offset while performing bound checks

§Errors
Source

pub fn try_write_u8_be_full(&mut self, v: u8) -> Result<&mut Self>

Write a BE-bit-order u8 while performing bound checks, advancing the internal cursor

§Errors
Source

pub fn write_u8_be_full_at(&mut self, offset: usize, v: u8) -> &mut Self

Write a BE-bit-order u8 at offset, panicking on out of bounds

§Panics
Source

pub fn write_u8_be_full(&mut self, v: u8) -> &mut Self

Write a BE-bit-order u8, panicking on out of bounds, advancing the internal cursor

§Panics
Source

pub unsafe fn write_u16_be_aligned_full_at_unchecked( &mut self, byte_offset: usize, v: u16, ) -> &mut Self

Write a u16 in [BE-bit, BE-byte] order at byte_offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn write_u16_be_aligned_full_unchecked( &mut self, v: u16, ) -> &mut Self

Write a u16 in [BE-bit, BE-byte] order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub unsafe fn write_u16_be_full_at_unchecked( &mut self, offset: usize, v: u16, ) -> &mut Self

Write a u16 in [BE-bit, BE-byte] order at offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn write_u16_be_full_unchecked(&mut self, v: u16) -> &mut Self

Write a u16 in [BE-bit, BE-byte] order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub fn try_write_u16_be_full_at( &mut self, offset: usize, v: u16, ) -> Result<&mut Self>

Write a [BE-bit, BE-byte] order u16 at offset while performing bound checks

§Errors
Source

pub fn try_write_u16_be_full(&mut self, v: u16) -> Result<&mut Self>

Write a [BE-bit, BE-byte] order u16 while performing bound checks, advancing the internal cursor

§Errors
Source

pub fn write_u16_be_full_at(&mut self, offset: usize, v: u16) -> &mut Self

Write a [BE-bit, BE-byte] order u16 at offset, panicking on out of bounds

§Panics
Source

pub fn write_u16_be_full(&mut self, v: u16) -> &mut Self

Write a [BE-bit, BE-byte] order u16, panicking on out of bounds, advancing the internal cursor

§Panics
Source

pub unsafe fn write_u32_be_aligned_full_at_unchecked( &mut self, byte_offset: usize, v: u32, ) -> &mut Self

Write a u32 in [BE-bit, BE-byte] order at byte_offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn write_u32_be_aligned_full_unchecked( &mut self, v: u32, ) -> &mut Self

Write a u32 in [BE-bit, BE-byte] order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub unsafe fn write_u32_be_full_at_unchecked( &mut self, offset: usize, v: u32, ) -> &mut Self

Write a u32 in [BE-bit, BE-byte] order at offset without performing bound checks

§Safety
§Panics
Source

pub unsafe fn write_u32_be_full_unchecked(&mut self, v: u32) -> &mut Self

Write a u32 in [BE-bit, BE-byte] order without performing bound checks, advancing the internal cursor

§Safety
§Panics
Source

pub fn try_write_u32_be_full_at( &mut self, offset: usize, v: u32, ) -> Result<&mut Self>

Write a [BE-bit, BE-byte] order u32 at offset while performing bound checks

§Errors
Source

pub fn try_write_u32_be_full(&mut self, v: u32) -> Result<&mut Self>

Write a [BE-bit, BE-byte] order u32 while performing bound checks, advancing the internal cursor

§Errors
Source

pub fn write_u32_be_full_at(&mut self, offset: usize, v: u32) -> &mut Self

Write a [BE-bit, BE-byte] order u32 at offset, panicking on out of bounds

§Panics
Source

pub fn write_u32_be_full(&mut self, v: u32) -> &mut Self

Write a [BE-bit, BE-byte] order u32, panicking on out of bounds, advancing the internal cursor

§Panics
Source§

impl<S: StorageMut> BitBuf<S>

Source

pub unsafe fn write_be_aligned_full_at_unchecked<T: Write>( &mut self, byte_offset: usize, v: T, ) -> &mut Self

Write a [BE-bit, BE-byte] order type T at byte_offset without performing bound checks

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub unsafe fn write_be_aligned_full_unchecked<T: Write>( &mut self, v: T, ) -> &mut Self

Write a [BE-bit, BE-byte] order type T without performing bound checks, advancing the internal cursor

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub unsafe fn write_be_full_at_unchecked<T: Write>( &mut self, offset: usize, v: T, ) -> &mut Self

Write a [BE-bit, BE-byte] order type T at offset without performing bound checks

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub unsafe fn write_be_full_unchecked<T: Write>(&mut self, v: T) -> &mut Self

Write a [BE-bit, BE-byte] order type T without performing bound checks, advancing the internal cursor

§Safety

All semantics of the corresponding function for the type apply

§Panics

All semantics of the corresponding function for the type apply

Source

pub fn try_write_be_full_at<T: Write>( &mut self, offset: usize, v: T, ) -> Result<&mut Self>

Write a [BE-bit, BE-byte] order type T at offset while performing bound checks

§Errors

All semantics of the corresponding function for the type apply

Source

pub fn try_write_be_full<T: Write>(&mut self, v: T) -> Result<&mut Self>

Write a [BE-bit, BE-byte] order type T while performing bound checks, advancing the internal cursor

§Errors

All semantics of the corresponding function for the type apply

Source

pub fn write_be_full_at<T: Write>(&mut self, offset: usize, v: T) -> &mut Self

Write a [BE-bit, BE-byte] order type T at offset, panicking on out of bounds

§Panics

All semantics of the corresponding function for the type apply

Source

pub fn write_be_full<T: Write>(&mut self, v: T) -> &mut Self

Write a [BE-bit, BE-byte] order type T, panicking on out of bounds, advancing the internal cursor

§Panics

All semantics of the corresponding function for the type apply

Trait Implementations§

Source§

impl<S: Debug> Debug for BitBuf<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> Freeze for BitBuf<S>
where S: Freeze,

§

impl<S> RefUnwindSafe for BitBuf<S>
where S: RefUnwindSafe,

§

impl<S> Send for BitBuf<S>
where S: Send,

§

impl<S> Sync for BitBuf<S>
where S: Sync,

§

impl<S> Unpin for BitBuf<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for BitBuf<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for BitBuf<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.