Skip to main content

BufferPool

Struct BufferPool 

Source
pub struct BufferPool<M: RawMutex, T, const N: usize> { /* private fields */ }
Expand description

Pool of N buffers of type T, synchronized with mutex M.

Free slots are tracked with a u32 bitmask, so N must be in 1..=32.

Implementations§

Source§

impl<M: RawMutex, T, const N: usize> BufferPool<M, T, N>

Source

pub const fn new(buffer: [T; N]) -> Self

Creates a pool with the given backing storage; all slots start available.

§Valid N

N must be in 1..=32. Otherwise BufferPool::new panics when run, or fails const evaluation if used in a const item.

Source

pub fn try_take(&'static self) -> Option<BufferGuard<M, T>>

Tries to take one buffer without blocking. Returns None if the pool is empty.

Source

pub fn take(&'static self) -> impl Future<Output = BufferGuard<M, T>>

Waits until a buffer is available, then returns a guard.

If the pool is empty, the current task’s waker is registered; when another task drops a BufferGuard or MappedBufferGuard, waiters are woken.

Trait Implementations§

Source§

impl<M: RawMutex + Send, T: Send, const N: usize> Send for BufferPool<M, T, N>

Source§

impl<M: RawMutex + Sync, T: Send, const N: usize> Sync for BufferPool<M, T, N>

Auto Trait Implementations§

§

impl<M, T, const N: usize> !Freeze for BufferPool<M, T, N>

§

impl<M, T, const N: usize> !RefUnwindSafe for BufferPool<M, T, N>

§

impl<M, T, const N: usize> Unpin for BufferPool<M, T, N>
where M: Unpin, T: Unpin,

§

impl<M, T, const N: usize> UnsafeUnpin for BufferPool<M, T, N>
where M: UnsafeUnpin, T: UnsafeUnpin,

§

impl<M, T, const N: usize> UnwindSafe for BufferPool<M, T, N>
where M: UnwindSafe, 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, 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.