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>
impl<T: ?Sized> LocalPooledMut<T>
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_mut("hello".to_string());
let pinned: Pin<&String> = handle.as_pin();
assert_eq!(pinned.len(), 5);Sourcepub fn as_pin_mut(&mut self) -> Pin<&mut T>
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 StringConverts 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>
impl<T: ?Sized> Debug for LocalPooledMut<T>
Source§impl<T: ?Sized> Deref for LocalPooledMut<T>
impl<T: ?Sized> Deref for LocalPooledMut<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_mut("hello".to_string());
// Access string methods directly.
assert_eq!(string_handle.len(), 5);
assert!(string_handle.starts_with("he"));Source§impl<T: ?Sized> DerefMut for LocalPooledMut<T>
impl<T: ?Sized> DerefMut for LocalPooledMut<T>
Source§fn deref_mut(&mut self) -> &mut Self::Target
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");