Struct HeapBuffer

Source
pub struct HeapBuffer<T>(/* private fields */);
Available on crate feature heap-buffer only.
Expand description

Backing buffer for a queue, allocated on the heap.

All queues require a backing buffer which implements the Storage trait. This buffer stores values in a contiguous array allocated on the heap. Compare this to StackBuffer which uses a contiguous array on the stack. Note that the asyncio, blocking and nonblocking queues move their buffer to the heap anyway.

§Example

use mini_io_queue::nonblocking;
use mini_io_queue::storage::HeapBuffer;

let buffer: HeapBuffer<u8> = HeapBuffer::new(100);
let (reader, writer) = nonblocking::queue_from(buffer);

Implementations§

Source§

impl<T> HeapBuffer<T>
where T: Default,

Source

pub fn new(capacity: usize) -> Self

Creates a buffer with the provided capacity. All elements in the buffer will be initialized to the item’s default value.

Trait Implementations§

Source§

impl<T> AsRef<[UnsafeCell<T>]> for HeapBuffer<T>

Source§

fn as_ref(&self) -> &[UnsafeCell<T>]

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<T> Debug for HeapBuffer<T>
where T: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> From<Box<[T]>> for HeapBuffer<T>

Source§

fn from(boxed_slice: Box<[T]>) -> Self

Converts to this type from the input type.
Source§

impl<T> Send for HeapBuffer<T>
where T: Send,

Source§

impl<T> Sync for HeapBuffer<T>
where T: Sync,

Auto Trait Implementations§

§

impl<T> Freeze for HeapBuffer<T>

§

impl<T> !RefUnwindSafe for HeapBuffer<T>

§

impl<T> Unpin for HeapBuffer<T>

§

impl<T> UnwindSafe for HeapBuffer<T>
where T: UnwindSafe,

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<T, A> Storage<T> for A
where A: AsRef<[UnsafeCell<T>]>,

Source§

fn capacity(&self) -> usize

Gets the capacity of the array, or in other words the upper bound for ranges passed into slice and slice_mut before they will panic.
Source§

fn slice(&self, range: Range<usize>) -> &[T]

Gets a slice of elements in the range provided. The length of the slice will always match the length of the range. Read more
Source§

unsafe fn slice_mut_unchecked(&self, range: Range<usize>) -> &mut [T]

Gets a mutable slice of elements in the range provided. The length of the slice will always match the length of the range. This function is unchecked and unsafe because it does not ensure there are no other references overlapping with the range, which is against Rust’s borrowing rules and is very unsafe! Read more
Source§

fn slice_mut(&mut self, range: Range<usize>) -> &mut [T]

Gets a mutable slice of elements in the range provided. The length of the slice will always match the length of the range. Read more
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.