mirror of
https://codeberg.org/icewind/bitbuffer.git
synced 2026-06-03 16:44:06 +02:00
bitwrite for options
This commit is contained in:
parent
5d7dbe35ee
commit
c321c5a252
2 changed files with 23 additions and 1 deletions
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "bitbuffer"
|
name = "bitbuffer"
|
||||||
version = "0.9.7"
|
version = "0.9.8"
|
||||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||||
edition = "2018"
|
edition = "2018"
|
||||||
description = "Reading bit sequences from a byte slice"
|
description = "Reading bit sequences from a byte slice"
|
||||||
|
|
|
||||||
22
src/write.rs
22
src/write.rs
|
|
@ -189,6 +189,17 @@ impl<T: BitWrite<E>, E: Endianness> BitWrite<E> for Vec<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: BitWrite<E>, E: Endianness> BitWrite<E> for Option<T> {
|
||||||
|
#[inline]
|
||||||
|
fn write(&self, stream: &mut BitWriteStream<E>) -> Result<()> {
|
||||||
|
self.is_some().write(stream)?;
|
||||||
|
if let Some(val) = self {
|
||||||
|
val.write(stream)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
macro_rules! impl_write_tuple {
|
macro_rules! impl_write_tuple {
|
||||||
($($i:tt: $type:ident),*) => {
|
($($i:tt: $type:ident),*) => {
|
||||||
impl<'a, E: Endianness, $($type: BitWrite<E>),*> BitWrite<E> for ($($type),*) {
|
impl<'a, E: Endianness, $($type: BitWrite<E>),*> BitWrite<E> for ($($type),*) {
|
||||||
|
|
@ -348,3 +359,14 @@ impl<T: BitWriteSized<E>, E: Endianness> BitWriteSized<E> for Arc<T> {
|
||||||
stream.write_sized(self.as_ref(), len)
|
stream.write_sized(self.as_ref(), len)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: BitWriteSized<E>, E: Endianness> BitWriteSized<E> for Option<T> {
|
||||||
|
#[inline]
|
||||||
|
fn write_sized(&self, stream: &mut BitWriteStream<E>, len: usize) -> Result<()> {
|
||||||
|
self.is_some().write(stream)?;
|
||||||
|
if let Some(val) = self {
|
||||||
|
val.write_sized(stream, len)?;
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue