pub struct SlabArc<const N: usize, const SZ: usize> { /* private fields */ }
Expand description
A reference counted, BSlab allocated chunk of bytes.
SlabArc
s implement the Deref
trait 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);
// Convert the Box into an Arc for sharing
let arc_1 = box_1.into_arc();
// And we can cheaply clone by increasing the reference count
let arc_1_1 = arc_1.clone();
// We can now send the arc to another thread
let hdl = spawn(move || {
arc_1.iter().enumerate().for_each(|(i, x)| assert_eq!(i as u8, *x));
});
// ... while still retaining a local handle to the same data
arc_1_1.iter().enumerate().for_each(|(i, x)| assert_eq!(i as u8, *x));
hdl.join();
}
Implementations§
Source§impl<const N: usize, const SZ: usize> SlabArc<N, SZ>
impl<const N: usize, const SZ: usize> SlabArc<N, SZ>
Sourcepub fn full_sub_slice_arc(&self) -> SlabSliceArc<N, SZ>
pub fn full_sub_slice_arc(&self) -> SlabSliceArc<N, SZ>
Create a SlabSliceArc
from this SlabArc
, with a full view
of the underlying data
pub fn rerooter_key<'a>(&'a self) -> RerooterKey<'a>
Sourcepub fn sub_slice_arc(
&self,
start: usize,
len: usize,
) -> Result<SlabSliceArc<N, SZ>, ()>
pub fn sub_slice_arc( &self, start: usize, len: usize, ) -> Result<SlabSliceArc<N, SZ>, ()>
Create a SlabSliceArc
from this SlabArc
, with a partial view
of the underlying data.
This function will fail if start
and len
do not describe a valid
region of the SlabArc
.
Trait Implementations§
Auto Trait Implementations§
impl<const N: usize, const SZ: usize> Freeze for SlabArc<N, SZ>
impl<const N: usize, const SZ: usize> !RefUnwindSafe for SlabArc<N, SZ>
impl<const N: usize, const SZ: usize> Send for SlabArc<N, SZ>
impl<const N: usize, const SZ: usize> Sync for SlabArc<N, SZ>
impl<const N: usize, const SZ: usize> Unpin for SlabArc<N, SZ>
impl<const N: usize, const SZ: usize> !UnwindSafe for SlabArc<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