pub struct StaticBuf<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> { /* private fields */ }Expand description
Static byte buffer. StaticBuf<[u8; 16]> can store a [u8] array from 0-16 bytes for example.
Unlike other static buffers, this does NOT reallocate if you out grow the internal buffer. If
you try to request more bytes than its able to store, it will panic.
Implementations§
Source§impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> StaticBuf<T, ArrayBuf>
impl<T: Copy, ArrayBuf: AsRef<[T]> + AsMut<[T]> + Default + Copy> StaticBuf<T, ArrayBuf>
pub fn new() -> Self
Sourcepub fn max_size() -> usize
pub fn max_size() -> usize
Returns the maximum size the StaticBuf can hold.
§Examples
use btle::bytes::StaticBuf;
assert_eq!(StaticBuf::<u8, [u8; 10]>::max_size(), 10);
assert_eq!(StaticBuf::<u8, [u8; 23]>::max_size(), 23);Sourcepub fn space_left(&self) -> usize
pub fn space_left(&self) -> usize
Returns the space left in Ts (not bytes) in the StaticBuf.
Simply (capacity - length).
Sourcepub fn resize(&mut self, new_size: usize)
pub fn resize(&mut self, new_size: usize)
Resizes the StaticBuf by settings self.len to new_size if new_size <= Self::max_size().
This is only a single variable change and WILL NOT zero or change any of the buffers bytes.
§Panics
Panics if the new size is greater than max_size (new_size > Self::max_size()).
§Examples
use btle::bytes::{StaticBuf, Storage};
let mut buf = StaticBuf::<u8, [u8; 10]>::with_size(10);
assert_eq!(buf.len(), 10);
assert_eq!(buf[9], 0);
buf[9] = 0xFF;
buf.resize(1);
assert_eq!(buf.len(), 1);
buf.resize(10);
assert_eq!(buf[9], 0xFF);Sourcepub fn append_slice(&mut self, slice: &[T])
pub fn append_slice(&mut self, slice: &[T])
Appends the slice onto the end of the StaticBuf.
§Panics
Panics if appending the slice would overflow the StaticBuf (not enough space).