LocalPooledMut

Struct LocalPooledMut 

Source
pub struct LocalPooledMut<T: ?Sized> { /* private fields */ }
Expand description

A mutable reference to a value stored in a LocalBlindPool.

This type provides automatic lifetime management for values in the pool with exclusive access. When the LocalPooledMut instance is dropped, the value is automatically removed from the pool.

Unlike LocalPooled<T>, this type does not implement Clone and provides exclusive access through DerefMut, making it suitable for scenarios where mutable access is required and shared ownership is not needed.

§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 mut value_handle = pool.insert_mut("Test".to_string());

// Mutably access the value.
value_handle.push_str(" - Modified");
assert_eq!(*value_handle, "Test - Modified");

// Value is automatically cleaned up when handle is dropped.

Implementations§

Source§

impl<T: ?Sized> LocalPooledMut<T>

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_mut("hello".to_string());

let pinned: Pin<&String> = handle.as_pin();
assert_eq!(pinned.len(), 5);
Source

pub fn as_pin_mut(&mut self) -> Pin<&mut T>

Returns a pinned mutable 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<&mut T> without requiring unsafe code.

§Example
use std::pin::Pin;

use blind_pool::LocalBlindPool;

let pool = LocalBlindPool::new();
let mut handle = pool.insert_mut("hello".to_string());

let mut pinned: Pin<&mut String> = handle.as_pin_mut();
// Can use Pin methods or deref to &mut String
Source

pub fn into_shared(self) -> LocalPooled<T>

Converts this exclusive LocalPooledMut<T> handle into a shared LocalPooled<T> handle.

This operation consumes the LocalPooledMut<T> and returns a LocalPooled<T> that allows multiple shared references to the same pooled value. Once converted, you can no longer obtain exclusive (mutable) references to the value, but you can create multiple shared references through cloning.

The returned LocalPooled<T> maintains the same lifetime management semantics - the value will be automatically removed from the pool when all references (including the returned LocalPooled<T>) are dropped.

§Example
use blind_pool::LocalBlindPool;

let pool = LocalBlindPool::new();
let mut exclusive_handle = pool.insert_mut("Test".to_string());

// Modify the value while we have exclusive access.
exclusive_handle.push_str(" - Modified");
assert_eq!(*exclusive_handle, "Test - Modified");

// Convert to shared access.
let shared_handle = exclusive_handle.into_shared();

// Now we can create multiple shared references.
let cloned_handle = shared_handle.clone();
assert_eq!(*shared_handle, "Test - Modified");
assert_eq!(*cloned_handle, "Test - Modified");

// Value is automatically cleaned up when all handles are dropped.

Trait Implementations§

Source§

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

Source§

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

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

impl<T: ?Sized> Deref for LocalPooledMut<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_mut("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.
Source§

impl<T: ?Sized> DerefMut for LocalPooledMut<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Provides direct mutable access to the value stored in the pool.

This allows the handle to be used as if it were a mutable reference to the stored value.

§Example
use blind_pool::LocalBlindPool;

let pool = LocalBlindPool::new();
let mut string_handle = pool.insert_mut("hello".to_string());

// Mutate the string directly.
string_handle.push_str(" world");
assert_eq!(*string_handle, "hello world");
Source§

impl<T: ?Sized> Drop for LocalPooledMut<T>

Source§

fn drop(&mut self)

Automatically removes the item from the pool when the handle is dropped.

This ensures that resources are properly cleaned up without requiring manual intervention.

Source§

impl<T: ?Sized> Unpin for LocalPooledMut<T>

Auto Trait Implementations§

§

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

§

impl<T> !RefUnwindSafe for LocalPooledMut<T>

§

impl<T> !Send for LocalPooledMut<T>

§

impl<T> !Sync for LocalPooledMut<T>

§

impl<T> !UnwindSafe for LocalPooledMut<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<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, 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.