Struct data_buffer::DataBuffer [−][src]
pub struct DataBuffer { /* fields omitted */ }Buffer of plain old data (POD). The data is stored as an array of bytes (Vec<u8>).
DataBuffer keeps track of the type stored within via an explicit TypeId member. This allows
one to hide the type from the compiler and check it only when necessary. It is particularly
useful when the type of data is determined at runtime (e.g. when parsing numeric data).
Methods
impl DataBuffer[src]
impl DataBufferpub fn new() -> Self[src]
pub fn new() -> SelfConstruct an empty DataBuffer
pub fn with_capacity<T: Any>(n: usize) -> Self[src]
pub fn with_capacity<T: Any>(n: usize) -> SelfConstruct a typed DataBuffer with a given size.
pub fn with_size<T: Any + Clone>(n: usize, def: T) -> Self[src]
pub fn with_size<T: Any + Clone>(n: usize, def: T) -> SelfConstruct a typed DataBuffer with a given size and filled with the specified default
value.
Examples
let buf = DataBuffer::with_size(8, 42usize); // Create buffer let buf_vec: Vec<usize> = buf.into_vec().unwrap(); // Convert into `Vec` assert_eq!(buf_vec, vec![42usize; 8]);
pub fn from_vec<T: Any>(vec: Vec<T>) -> Self[src]
pub fn from_vec<T: Any>(vec: Vec<T>) -> SelfConstruct a DataBuffer from a given Vec<T> reusing the space already allocated by the
given vector.
Examples
let vec = vec![1u8, 3, 4, 1, 2]; let buf = DataBuffer::from_vec(vec.clone()); // Convert into buffer let nu_vec: Vec<u8> = buf.into_vec().unwrap(); // Convert back into `Vec` assert_eq!(vec, nu_vec);
pub fn from_slice<T: Any>(slice: &[T]) -> Self[src]
pub fn from_slice<T: Any>(slice: &[T]) -> SelfConstruct a DataBuffer from a given slice by copying the data.
pub fn copy_from_slice<T: Any>(&mut self, slice: &[T]) -> &mut Self[src]
pub fn copy_from_slice<T: Any>(&mut self, slice: &[T]) -> &mut SelfCopy data from a given slice into the current buffer.
pub fn clear(&mut self)[src]
pub fn clear(&mut self)Clear the data buffer and set length to zero.
pub fn fill<T: Any + Clone>(&mut self, def: T) -> Option<&mut Self>[src]
pub fn fill<T: Any + Clone>(&mut self, def: T) -> Option<&mut Self>Fill the current buffer with copies of the given value. The size of the buffer is left
unchanged. If the given type doesn't patch the internal type, None is returned, otherwise
a mut reference to the modified buffer is returned.
Examples
let vec = vec![1u8, 3, 4, 1, 2]; let mut buf = DataBuffer::from_vec(vec.clone()); // Convert into buffer buf.fill(0u8); assert_eq!(buf.into_vec::<u8>().unwrap(), vec![0u8, 0, 0, 0, 0]);
pub fn check<T: Any>(self) -> Option<Self>[src]
pub fn check<T: Any>(self) -> Option<Self>Check if the current buffer contains elements of the specified type. Returns Some(self)
if the type matches and None otherwise.
pub fn check_ref<T: Any>(&self) -> Option<&Self>[src]
pub fn check_ref<T: Any>(&self) -> Option<&Self>Check if the current buffer contains elements of the specified type. Returns None if the
check fails, otherwise a reference to self is returned.
pub fn check_mut<T: Any>(&mut self) -> Option<&mut Self>[src]
pub fn check_mut<T: Any>(&mut self) -> Option<&mut Self>Check if the current buffer contains elements of the specified type. Same as check_ref
but consumes and produces a mut reference to self.
pub fn type_id(&self) -> TypeId[src]
pub fn type_id(&self) -> TypeIdGet the TypeId of data stored within this buffer.
pub fn len(&self) -> usize[src]
pub fn len(&self) -> usizeGet the number of elements stored in this buffer.
pub fn iter<'a, T: Any + 'a>(&'a self) -> Option<Iter<T>>[src]
pub fn iter<'a, T: Any + 'a>(&'a self) -> Option<Iter<T>>Return an iterator to a slice representing typed data.
Returs None if the given type T doesn't match the internal.
Examples
let vec = vec![1.0_f32, 23.0, 0.01, 42.0, 11.43]; let buf = DataBuffer::from(vec.clone()); // Convert into buffer for (i, &val) in buf.iter::<f32>().unwrap().enumerate() { assert_eq!(val, vec[i]); }
pub fn iter_mut<'a, T: Any + 'a>(&'a mut self) -> Option<IterMut<T>>[src]
pub fn iter_mut<'a, T: Any + 'a>(&'a mut self) -> Option<IterMut<T>>Return an iterator to a mutable slice representing typed data.
Returs None if the given type T doesn't match the internal.
pub fn append_clone_to_vec<'a, T>(
&self,
vec: &'a mut Vec<T>
) -> Option<&'a mut Vec<T>> where
T: Any + Clone, [src]
pub fn append_clone_to_vec<'a, T>(
&self,
vec: &'a mut Vec<T>
) -> Option<&'a mut Vec<T>> where
T: Any + Clone, Append cloned items from this buffer to a given Vec<T>. Return the mutable reference
Some(vec) if type matched the internal type and None otherwise.
pub fn append_copy_to_vec<'a, T>(
&self,
vec: &'a mut Vec<T>
) -> Option<&'a mut Vec<T>> where
T: Any + Copy, [src]
pub fn append_copy_to_vec<'a, T>(
&self,
vec: &'a mut Vec<T>
) -> Option<&'a mut Vec<T>> where
T: Any + Copy, Append copied items from this buffer to a given Vec<T>. Return the mutable reference
Some(vec) if type matched the internal type and None otherwise. This may be faster than
append_clone_to_vec.
pub fn clone_into_vec<T: Any + Clone>(&self) -> Option<Vec<T>>[src]
pub fn clone_into_vec<T: Any + Clone>(&self) -> Option<Vec<T>>Clones contents of self into the given Vec.
pub fn copy_into_vec<T: Any + Copy>(&self) -> Option<Vec<T>>[src]
pub fn copy_into_vec<T: Any + Copy>(&self) -> Option<Vec<T>>Copies contents of self into the given Vec.
pub fn into_vec<T: Any>(self) -> Option<Vec<T>>[src]
pub fn into_vec<T: Any>(self) -> Option<Vec<T>>An alternative to using the Into trait. This function helps the compiler
determine the type T automatically.
pub fn as_slice<T: Any>(&self) -> Option<&[T]>[src]
pub fn as_slice<T: Any>(&self) -> Option<&[T]>Convert this buffer into a typed slice.
Returs None if the given type T doesn't match the internal.
pub fn as_mut_slice<T: Any>(&mut self) -> Option<&mut [T]>[src]
pub fn as_mut_slice<T: Any>(&mut self) -> Option<&mut [T]>Convert this buffer into a typed mutable slice.
Returs None if the given type T doesn't match the internal.
pub fn get<T: Any + Copy>(&self, i: usize) -> Option<T>[src]
pub fn get<T: Any + Copy>(&self, i: usize) -> Option<T>Get i'th element of the buffer by value.
pub fn get_ref<T: Any>(&self, i: usize) -> Option<&T>[src]
pub fn get_ref<T: Any>(&self, i: usize) -> Option<&T>Get a const reference to the i'th element of the buffer.
pub fn get_mut<T: Any>(&mut self, i: usize) -> Option<&mut T>[src]
pub fn get_mut<T: Any>(&mut self, i: usize) -> Option<&mut T>Get a mutable reference to the i'th element of the buffer.
pub unsafe fn get_unchecked<T: Any + Copy>(&self, i: usize) -> T[src]
pub unsafe fn get_unchecked<T: Any + Copy>(&self, i: usize) -> TGet i'th element of the buffer by value without checking type.
This can be used to reinterpret the internal data as a different type. Note that if the
size of the given type T doesn't match the size of the internal type, i will really
index the ith T sized chunk in the current buffer. See the implementation for details.
pub unsafe fn get_unchecked_ref<T: Any>(&self, i: usize) -> &T[src]
pub unsafe fn get_unchecked_ref<T: Any>(&self, i: usize) -> &TGet a const reference to the i'th element of the buffer.
This can be used to reinterpret the internal data as a different type. Note that if the
size of the given type T doesn't match the size of the internal type, i will really
index the ith T sized chunk in the current buffer. See the implementation for details.
pub unsafe fn get_unchecked_mut<T: Any>(&mut self, i: usize) -> &mut T[src]
pub unsafe fn get_unchecked_mut<T: Any>(&mut self, i: usize) -> &mut TGet a mutable reference to the i'th element of the buffer.
This can be used to reinterpret the internal data as a different type. Note that if the
size of the given type T doesn't match the size of the internal type, i will really
index the ith T sized chunk in the current buffer. See the implementation for details.
pub fn reinterpret_as_vec<T>(self) -> Vec<T>[src]
pub fn reinterpret_as_vec<T>(self) -> Vec<T>Move buffer data to a vector with a given type, reinterpreting the data type as required.
pub fn reinterpret_as_slice<T>(&self) -> &[T][src]
pub fn reinterpret_as_slice<T>(&self) -> &[T]Borrow buffer data and reinterpret it as a slice of a given type.
pub fn reinterpret_as_mut_slice<T>(&mut self) -> &mut [T][src]
pub fn reinterpret_as_mut_slice<T>(&mut self) -> &mut [T]Mutably borrow buffer data and reinterpret it as a mutable slice of a given type.
pub fn reinterpret_iter<T>(&self) -> Iter<T>[src]
pub fn reinterpret_iter<T>(&self) -> Iter<T>Borrow buffer data and iterate over reinterpreted underlying data.
pub fn reinterpret_iter_mut<T>(&mut self) -> IterMut<T>[src]
pub fn reinterpret_iter_mut<T>(&mut self) -> IterMut<T>Mutably borrow buffer data and mutably iterate over reinterpreted underlying data.
pub fn raw_data(&self) -> &Vec<u8>[src]
pub fn raw_data(&self) -> &Vec<u8>Peak at the internal representation of the data.
pub fn raw_mut_data(&mut self) -> &mut Vec<u8>[src]
pub fn raw_mut_data(&mut self) -> &mut Vec<u8>Get a mutable reference to the internal data representation.
Trait Implementations
impl Clone for DataBuffer[src]
impl Clone for DataBufferfn clone(&self) -> DataBuffer[src]
fn clone(&self) -> DataBufferReturns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)1.0.0[src]
fn clone_from(&mut self, source: &Self)Performs copy-assignment from source. Read more
impl Debug for DataBuffer[src]
impl Debug for DataBufferfn fmt(&self, f: &mut Formatter) -> Result[src]
fn fmt(&self, f: &mut Formatter) -> ResultFormats the value using the given formatter. Read more
impl PartialEq for DataBuffer[src]
impl PartialEq for DataBufferfn eq(&self, other: &DataBuffer) -> bool[src]
fn eq(&self, other: &DataBuffer) -> boolThis method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &DataBuffer) -> bool[src]
fn ne(&self, other: &DataBuffer) -> boolThis method tests for !=.
impl Hash for DataBuffer[src]
impl Hash for DataBufferfn hash<__H: Hasher>(&self, state: &mut __H)[src]
fn hash<__H: Hasher>(&self, state: &mut __H)Feeds this value into the given [Hasher]. Read more
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, 1.3.0[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher, Feeds a slice of this type into the given [Hasher]. Read more
impl<T> From<Vec<T>> for DataBuffer where
T: Any, [src]
impl<T> From<Vec<T>> for DataBuffer where
T: Any, Convert a Vec<T> to a DataBuffer.
fn from(vec: Vec<T>) -> DataBuffer[src]
fn from(vec: Vec<T>) -> DataBufferPerforms the conversion.
impl<'a, T> From<&'a [T]> for DataBuffer where
T: Any, [src]
impl<'a, T> From<&'a [T]> for DataBuffer where
T: Any, Convert a &[T] to a DataBuffer.
fn from(slice: &'a [T]) -> DataBuffer[src]
fn from(slice: &'a [T]) -> DataBufferPerforms the conversion.
impl<T> Into<Option<Vec<T>>> for DataBuffer where
T: Any + Clone, [src]
impl<T> Into<Option<Vec<T>>> for DataBuffer where
T: Any + Clone, Convert a DataBuffer to a Option<Vec<T>>.
Auto Trait Implementations
impl Send for DataBuffer
impl Send for DataBufferimpl Sync for DataBuffer
impl Sync for DataBuffer