pub struct SlabBox<const N: usize, const SZ: usize> { /* private fields */ }
Expand description
An owned, BSlab allocated chunk of bytes.
SlabBox
s implement the Deref
and DerefMut
traits for access to
the underlying allocation
§Example
use byte_slab::BSlab;
use std::thread::spawn;
static SLAB: BSlab<4, 128> = BSlab::new();
fn main() {
// Initialize the byte slab
SLAB.init().unwrap();
let mut box_1 = SLAB.alloc_box().unwrap();
// Fill
assert_eq!(box_1.len(), 128);
box_1.iter_mut().enumerate().for_each(|(i, x)| *x = i as u8);
// We can now send the box to another thread
let hdl = spawn(move || {
box_1.iter().enumerate().for_each(|(i, x)| assert_eq!(i as u8, *x));
});
hdl.join();
}
Implementations§
Trait Implementations§
impl<const N: usize, const SZ: usize> Send for SlabBox<N, SZ>
Auto Trait Implementations§
impl<const N: usize, const SZ: usize> Freeze for SlabBox<N, SZ>
impl<const N: usize, const SZ: usize> !RefUnwindSafe for SlabBox<N, SZ>
impl<const N: usize, const SZ: usize> Sync for SlabBox<N, SZ>
impl<const N: usize, const SZ: usize> Unpin for SlabBox<N, SZ>
impl<const N: usize, const SZ: usize> !UnwindSafe for SlabBox<N, SZ>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more