SlabBox

Struct SlabBox 

Source
pub struct SlabBox<const N: usize, const SZ: usize> { /* private fields */ }
Expand description

An owned, BSlab allocated chunk of bytes.

SlabBoxs 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§

Source§

impl<const N: usize, const SZ: usize> SlabBox<N, SZ>

Source

pub fn into_arc(self) -> SlabArc<N, SZ>

Convert the SlabBox into a SlabArc.

This loses the ability to mutate the data within the allocation, but the may now be shared to multiple locations using reference counts

Trait Implementations§

Source§

impl<const N: usize, const SZ: usize> Deref for SlabBox<N, SZ>

Source§

type Target = [u8; SZ]

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<const N: usize, const SZ: usize> DerefMut for SlabBox<N, SZ>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<const N: usize, const SZ: usize> Drop for SlabBox<N, SZ>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.