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>
impl<T> Pooled<T>
Sourcepub fn ptr(&self) -> NonNull<T>
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);Sourcepub fn erase(self) -> Pooled<()>
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);