Struct Pooled

Source
pub struct Pooled<T> { /* private fields */ }
Expand description

A handle representing an item stored in a BlindPool.

This provides access to the stored item and can be used to remove the item from the pool.

§Example

use blind_pool::BlindPool;

let mut pool = BlindPool::new();

let pooled = pool.insert(42_u64);

// Access the value via the pointer.
// SAFETY: The pointer is valid and contains the value we just inserted.
let value = unsafe { pooled.ptr().read() };
assert_eq!(value, 42);

// Remove the item from the pool.
pool.remove(pooled);

Implementations§

Source§

impl<T> Pooled<T>

Source

pub fn ptr(&self) -> NonNull<T>

Returns a pointer to the inserted value.

This is the only way to access the value stored in the pool. The owner of the handle has exclusive access to the value and may both read and write and may create both & shared and &mut exclusive references to the item.

§Example
use blind_pool::BlindPool;

let mut pool = BlindPool::new();

let pooled = pool.insert(2.5159_f64);

// Read data back from the memory.
// SAFETY: The pointer is valid and the memory contains the value we just inserted.
let value = unsafe { pooled.ptr().read() };
assert_eq!(value, 2.5159);
Source

pub fn erase(self) -> Pooled<()>

Erases the type information from this Pooled<T> handle, returning a [Pooled<()>].

This is useful when you want to store handles of different types in the same collection or pass them to code that doesn’t need to know the specific type.

The handle remains functionally equivalent and can still be used to remove the item from the pool and drop it. The only change is the removal of the type information.

§Example
use blind_pool::BlindPool;

let mut pool = BlindPool::new();

let pooled = pool.insert(42_u64);

// Erase type information.
let erased = pooled.erase();

// Can still access the raw pointer.
// SAFETY: We know this contains a u64.
let value = unsafe { erased.ptr().cast::<u64>().read() };
assert_eq!(value, 42);

// Can still remove the item.
pool.remove(erased);

Trait Implementations§

Source§

impl<T: Debug> Debug for Pooled<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Pooled<T>

§

impl<T> RefUnwindSafe for Pooled<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Pooled<T>

§

impl<T> !Sync for Pooled<T>

§

impl<T> Unpin for Pooled<T>

§

impl<T> UnwindSafe for Pooled<T>
where T: RefUnwindSafe,

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.