LocalPooled

Struct LocalPooled 

Source
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>

Source

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.
Source

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");
Source

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>

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<T: ?Sized> Debug for LocalPooled<T>

Source§

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

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

impl<T: ?Sized> Deref for LocalPooled<T>

Source§

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"));
Source§

type Target = T

The resulting type after dereferencing.

Auto Trait Implementations§

§

impl<T> Freeze for LocalPooled<T>
where T: ?Sized,

§

impl<T> !RefUnwindSafe for LocalPooled<T>

§

impl<T> !Send for LocalPooled<T>

§

impl<T> !Sync for LocalPooled<T>

§

impl<T> Unpin for LocalPooled<T>
where T: ?Sized,

§

impl<T> !UnwindSafe for LocalPooled<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.