1
0
Fork 0
mirror of https://codeberg.org/icewind/bitbuffer.git synced 2026-06-03 16:44:06 +02:00

add BitRead implementations for Rc/Arc

This commit is contained in:
Robin Appelman 2019-08-26 20:18:11 +02:00
commit 5856dd3ade

View file

@ -5,6 +5,8 @@ use std::collections::HashMap;
use std::hash::Hash; use std::hash::Hash;
use std::marker::PhantomData; use std::marker::PhantomData;
use std::mem::size_of; use std::mem::size_of;
use std::rc::Rc;
use std::sync::Arc;
/// Trait for types that can be read from a stream without requiring the size to be configured /// Trait for types that can be read from a stream without requiring the size to be configured
/// ///
@ -222,6 +224,20 @@ impl<E: Endianness> BitRead<E> for String {
} }
} }
impl<E: Endianness, T: BitRead<E>> BitRead<E> for Rc<T> {
#[inline]
fn read(stream: &mut BitStream<E>) -> Result<Self> {
Ok(Rc::new(T::read(stream)?))
}
}
impl<E: Endianness, T: BitRead<E>> BitRead<E> for Arc<T> {
#[inline]
fn read(stream: &mut BitStream<E>) -> Result<Self> {
Ok(Arc::new(T::read(stream)?))
}
}
/// Trait for types that can be read from a stream, 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, /// The meaning of the set sized depends on the type being read (e.g, number of bits for integers,