pub struct LocalPooled<T: ?Sized> { /* private fields */ }Expand description
A reference to a value stored in a LocalBlindPool.
This type provides automatic lifetime management for values in the pool.
When the last LocalPooled instance for a value is dropped, the value
is automatically removed from the pool.
Multiple LocalPooled instances can reference the same value through
cloning, implementing reference counting semantics.
§Single-threaded Design
This type is designed for single-threaded use and is neither Send nor Sync.
§Example
use blind_pool::LocalBlindPool;
let pool = LocalBlindPool::new();
let value_handle = pool.insert("Test".to_string());
// Access the value through dereferencing.
assert_eq!(*value_handle, "Test".to_string());
// Clone to create additional references.
let cloned_handle = value_handle.clone();
assert_eq!(*cloned_handle, "Test".to_string());Implementations§
Source§impl<T: ?Sized> LocalPooled<T>
impl<T: ?Sized> LocalPooled<T>
Sourcepub fn erase(self) -> LocalPooled<()>
pub fn erase(self) -> LocalPooled<()>
Erases the type information from this LocalPooled<T> handle,
returning a LocalPooled<()>.
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 returned handle shares the same underlying reference count as the original handle. Multiple handles (both typed and type-erased) can coexist for the same pooled item, and the item will only be removed from the pool when all handles are dropped.
§Example
use blind_pool::LocalBlindPool;
let pool = LocalBlindPool::new();
let value_handle = pool.insert("Test".to_string());
let cloned_handle = value_handle.clone();
// Erase type information while keeping the original handle via clone.
let erased = value_handle.erase();
// Both handles are valid and refer to the same item.
assert_eq!(*cloned_handle, "Test".to_string());
// The erased handle shares the same reference count.
drop(erased);
assert_eq!(*cloned_handle, "Test".to_string()); // Still accessible via typed handle.Sourcepub fn ptr(&self) -> NonNull<T>
pub fn ptr(&self) -> NonNull<T>
Returns a pointer to the stored value.
This provides direct access to the underlying pointer while maintaining the safety
guarantees of the pooled reference. The pointer remains valid as long as any
LocalPooled<T> handle exists for the same value.
§Example
use blind_pool::LocalBlindPool;
let pool = LocalBlindPool::new();
let value_handle = pool.insert("Test".to_string());
// Get the pointer to the stored value.
let ptr = value_handle.ptr();
// SAFETY: The pointer is valid as long as value_handle exists.
let value = unsafe { ptr.as_ref() };
assert_eq!(value, "Test");Sourcepub fn as_pin(&self) -> Pin<&T>
pub fn as_pin(&self) -> Pin<&T>
Returns a pinned reference to the value stored in the pool.
Since values in the pool are always pinned (they never move once inserted),
this method provides safe access to Pin<&T> without requiring unsafe code.
§Example
use std::pin::Pin;
use blind_pool::LocalBlindPool;
let pool = LocalBlindPool::new();
let handle = pool.insert("hello".to_string());
let pinned: Pin<&String> = handle.as_pin();
assert_eq!(pinned.len(), 5);Trait Implementations§
Source§impl<T: ?Sized> Clone for LocalPooled<T>
impl<T: ?Sized> Clone for LocalPooled<T>
Source§fn clone(&self) -> Self
fn clone(&self) -> Self
Creates another handle to the same pooled value.
This increases the reference count for the underlying value. The value will only be removed from the pool when all cloned handles are dropped.
§Example
use blind_pool::LocalBlindPool;
let pool = LocalBlindPool::new();
let value_handle = pool.insert("Test".to_string());
let cloned_handle = value_handle.clone();
// Both handles refer to the same value.
assert_eq!(*value_handle, *cloned_handle);
// Value remains in pool until all handles are dropped.
drop(value_handle);
assert_eq!(*cloned_handle, "Test".to_string()); // Still accessible.1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: ?Sized> Debug for LocalPooled<T>
impl<T: ?Sized> Debug for LocalPooled<T>
Source§impl<T: ?Sized> Deref for LocalPooled<T>
impl<T: ?Sized> Deref for LocalPooled<T>
Source§fn deref(&self) -> &Self::Target
fn deref(&self) -> &Self::Target
Provides direct access to the value stored in the pool.
This allows the handle to be used as if it were a reference to the stored value.
§Example
use blind_pool::LocalBlindPool;
let pool = LocalBlindPool::new();
let string_handle = pool.insert("hello".to_string());
// Access string methods directly.
assert_eq!(string_handle.len(), 5);
assert!(string_handle.starts_with("he"));