mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
format
This commit is contained in:
parent
7f491a7793
commit
aba52326be
1 changed files with 23 additions and 20 deletions
17
src/lib.rs
17
src/lib.rs
|
|
@ -5,8 +5,8 @@
|
|||
// for bench on nightly
|
||||
//extern crate test;
|
||||
|
||||
pub use endianness::{BigEndian, LittleEndian};
|
||||
use endianness::Endianness;
|
||||
pub use endianness::{BigEndian, LittleEndian};
|
||||
use is_signed::IsSigned;
|
||||
use num_traits::{Float, PrimInt};
|
||||
use std::cmp::min;
|
||||
|
|
@ -66,7 +66,6 @@ impl IsPadded for Padded {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
/// Either the read bits in the requested format or a [`ReadError`](enum.ReadError.html)
|
||||
pub type Result<T> = std::result::Result<T, ReadError>;
|
||||
|
||||
|
|
@ -100,7 +99,7 @@ pub type Result<T> = std::result::Result<T, ReadError>;
|
|||
pub struct BitBuffer<'a, E, S>
|
||||
where
|
||||
E: Endianness,
|
||||
S: IsPadded
|
||||
S: IsPadded,
|
||||
{
|
||||
bytes: &'a [u8],
|
||||
bit_len: usize,
|
||||
|
|
@ -111,7 +110,7 @@ pub struct BitBuffer<'a, E, S>
|
|||
|
||||
impl<'a, E> BitBuffer<'a, E, NonPadded>
|
||||
where
|
||||
E: Endianness
|
||||
E: Endianness,
|
||||
{
|
||||
/// Create a new BitBuffer from a byte slice
|
||||
///
|
||||
|
|
@ -140,7 +139,7 @@ impl<'a, E> BitBuffer<'a, E, NonPadded>
|
|||
|
||||
impl<'a, E> BitBuffer<'a, E, Padded>
|
||||
where
|
||||
E: Endianness
|
||||
E: Endianness,
|
||||
{
|
||||
/// Create a new BitBuffer from a byte slice with included padding
|
||||
///
|
||||
|
|
@ -164,7 +163,11 @@ impl<'a, E> BitBuffer<'a, E, Padded>
|
|||
/// ```
|
||||
pub fn from_padded_slice(bytes: &'a [u8], byte_len: usize, _endianness: E) -> Self {
|
||||
if bytes.len() < byte_len + USIZE_SIZE - 1 {
|
||||
panic!("not enough padding bytes, {} required, {} provided", USIZE_SIZE - 1, byte_len - bytes.len())
|
||||
panic!(
|
||||
"not enough padding bytes, {} required, {} provided",
|
||||
USIZE_SIZE - 1,
|
||||
byte_len - bytes.len()
|
||||
)
|
||||
}
|
||||
BitBuffer {
|
||||
bytes,
|
||||
|
|
@ -179,7 +182,7 @@ impl<'a, E> BitBuffer<'a, E, Padded>
|
|||
impl<'a, E, S> BitBuffer<'a, E, S>
|
||||
where
|
||||
E: Endianness,
|
||||
S: IsPadded
|
||||
S: IsPadded,
|
||||
{
|
||||
/// The available number of bits in the buffer
|
||||
pub fn bit_len(&self) -> usize {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue