mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
add trait for skipping types
This commit is contained in:
parent
7b222158f1
commit
b723dee23b
4 changed files with 29 additions and 1 deletions
|
|
@ -62,7 +62,7 @@ pub use std::string::FromUtf8Error;
|
|||
pub use bitstream_reader_derive::{BitRead, BitReadSized, BitSize, BitSizeSized};
|
||||
pub use buffer::BitBuffer;
|
||||
pub use endianness::*;
|
||||
pub use read::{BitRead, BitReadSized, BitSize, BitSizeSized, LazyBitRead, LazyBitReadSized};
|
||||
pub use read::{BitRead, BitReadSized, BitSize, BitSizeSized, LazyBitRead, LazyBitReadSized, BitSkip};
|
||||
pub use stream::BitStream;
|
||||
|
||||
mod buffer;
|
||||
|
|
|
|||
16
src/read.rs
16
src/read.rs
|
|
@ -95,6 +95,22 @@ pub trait BitSize {
|
|||
fn bit_size() -> usize;
|
||||
}
|
||||
|
||||
/// Trait to allow skipping a type
|
||||
///
|
||||
/// This might be faster than trying to read it
|
||||
pub trait BitSkip<E: Endianness>: BitRead<E> {
|
||||
/// Skip the type
|
||||
fn skip(stream: &mut BitStream<E>) -> Result<()> {
|
||||
Self::read(stream).map(|_| ())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: BitRead<E> + BitSize, E: Endianness> BitSkip<E> for T {
|
||||
fn skip(stream: &mut BitStream<E>) -> Result<()> {
|
||||
stream.skip_bits(Self::bit_size())
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! impl_read_int {
|
||||
($type:ty, $len:expr) => {
|
||||
impl<E: Endianness> BitRead<E> for $type {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue