RawEventPool

Struct RawEventPool 

Source
pub struct RawEventPool<T: Send + 'static> { /* private fields */ }
Expand description

A pool of reusable thread-safe one-time events with manual pool lifecycle management.

§Examples

use events_once::RawEventPool;

let pool = Box::pin(RawEventPool::<String>::new());

for i in 0..3 {
    // SAFETY: We promise the pool outlives both the returned endpoints.
    let (tx, rx) = unsafe { pool.as_ref().rent() };

    tx.send(format!("Message {i}"));

    let message = rx.await.unwrap();
    println!("{message}");
}

Implementations§

Source§

impl<T: Send + 'static> RawEventPool<T>

Source

pub fn new() -> Self

Creates a new empty event pool.

Source

pub unsafe fn rent( self: Pin<&Self>, ) -> (RawPooledSender<T>, RawPooledReceiver<T>)

Rents an event from the pool, returning its endpoints.

The event will be returned to the pool when both endpoints are dropped.

§Safety

The caller must guarantee that the pool outlives the endpoints.

Source

pub fn is_empty(&self) -> bool

Returns true if no events have currently been rented from the pool.

Source

pub fn len(&self) -> usize

Returns the number of events that have currently been rented from the pool.

Source

pub fn inspect_awaiters(&self, f: impl FnMut(&Backtrace))

Uses the provided closure to inspect the backtraces of the most recent awaiter of each awaited event in the pool.

This method is only available in debug builds (cfg(debug_assertions)). For any data to be present, RUST_BACKTRACE=1 or RUST_LIB_BACKTRACE=1 must be set.

The closure is called once for each event in the pool that has been awaited at some point in the past.

Trait Implementations§

Source§

impl<T: Send + 'static> Debug for RawEventPool<T>

Source§

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

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

impl<T: Send + 'static> Default for RawEventPool<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Send + 'static> Drop for RawEventPool<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T: Send + 'static> Send for RawEventPool<T>

Source§

impl<T: Send + 'static> Sync for RawEventPool<T>

Auto Trait Implementations§

§

impl<T> Freeze for RawEventPool<T>

§

impl<T> !RefUnwindSafe for RawEventPool<T>

§

impl<T> Unpin for RawEventPool<T>
where T: Unpin,

§

impl<T> !UnwindSafe for RawEventPool<T>

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.