mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
impl ReadSized for BitStream
This commit is contained in:
parent
af83f5e3b3
commit
4bf39b874d
3 changed files with 13 additions and 3 deletions
12
src/read.rs
12
src/read.rs
|
|
@ -84,7 +84,10 @@ impl<E: Endianness> BitRead<E> for String {
|
|||
}
|
||||
}
|
||||
|
||||
/// Trait for types that can be read from a stream wit requiring the size to be configured
|
||||
/// Trait for types that can be read from a stream, requiring the size to be configured
|
||||
///
|
||||
/// The meaning of the set sized depends on the type being read (e.g, number of bits for integers,
|
||||
/// number of bytes for strings, number of items for Vec's, etc)
|
||||
pub trait BitReadSized<E: Endianness>: Sized {
|
||||
/// Read the type from stream
|
||||
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self>;
|
||||
|
|
@ -130,6 +133,13 @@ impl<E: Endianness, T: BitRead<E>> BitRead<E> for Option<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<E: Endianness> BitReadSized<E> for BitStream<E> {
|
||||
#[inline(always)]
|
||||
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self> {
|
||||
stream.read_bits(size)
|
||||
}
|
||||
}
|
||||
|
||||
/// Read `T` `size` times and return as `Vec<T>`
|
||||
impl<E: Endianness, T: BitRead<E>> BitReadSized<E> for Vec<T> {
|
||||
fn read(stream: &mut BitStream<E>, size: usize) -> Result<Self> {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use num_traits::{Float, PrimInt};
|
|||
use crate::endianness::Endianness;
|
||||
use crate::is_signed::IsSigned;
|
||||
use crate::BitBuffer;
|
||||
use crate::{BitRead, ReadError, BitReadSized, Result};
|
||||
use crate::{BitRead, BitReadSized, ReadError, Result};
|
||||
|
||||
/// Stream that provides an easy way to iterate trough a [`BitBuffer`]
|
||||
///
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue