pub struct PooledMut<T: ?Sized> { /* private fields */ }Expand description
A mutable reference to a value stored in a BlindPool.
This type provides automatic lifetime management for values in the pool with exclusive access.
When the PooledMut instance is dropped, the value is automatically removed from the pool.
Unlike Pooled<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.
§Thread Safety
PooledMut<T> implements thread safety traits conditionally based on the stored type T:
-
Send:
PooledMut<T>isSendif and only ifTisSend. This allows moving pooled mutable references between threads when the referenced type can be moved between threads. -
Sync:
PooledMut<T>does NOT implementSyncbecause it provides exclusive mutable access viaDerefMut. Allowing multiple threads to share references to the samePooledMut<T>instance would violate Rust’s borrowing rules and lead to data races.
§Example
use blind_pool::BlindPool;
let pool = BlindPool::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> PooledMut<T>
impl<T: ?Sized> PooledMut<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::BlindPool;
let pool = BlindPool::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::BlindPool;
let pool = BlindPool::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 PooledMut<T> handle into a shared Pooled<T> handle.
This operation consumes the PooledMut<T> and returns a Pooled<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 Pooled<T> maintains the same lifetime management semantics -
the value will be automatically removed from the pool when all references
(including the returned Pooled<T>) are dropped.
§Example
use blind_pool::BlindPool;
let pool = BlindPool::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.Source§impl<T: Unpin> PooledMut<T>
impl<T: Unpin> PooledMut<T>
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Moves the value out of the pool, returning it to the caller and consuming the PooledMut<T>.
This method extracts the value from the pool and transfers ownership to the caller. The item is removed from the pool, but the value is not dropped - instead, it is returned to the caller who becomes responsible for its lifetime management.
This method is only available for types that implement Unpin, as moving a value
out of the pool would break the pinning guarantee for !Unpin types.
§Example
use blind_pool::BlindPool;
let pool = BlindPool::new();
let mut pooled_string = pool.insert_mut("Hello".to_string());
// Modify the value while it is in the pool.
pooled_string.push_str(" World");
assert_eq!(*pooled_string, "Hello World");
assert_eq!(pool.len(), 1);
// Extract the value from the pool.
let extracted_string = pooled_string.into_inner();
assert_eq!(extracted_string, "Hello World");
assert_eq!(pool.len(), 0); // Pool is now empty.
// The caller now owns the value and is responsible for its lifetime.
println!("Extracted: {}", extracted_string);Trait Implementations§
Source§impl<T: ?Sized> Deref for PooledMut<T>
impl<T: ?Sized> Deref for PooledMut<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::BlindPool;
let pool = BlindPool::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 PooledMut<T>
impl<T: ?Sized> DerefMut for PooledMut<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::BlindPool;
let pool = BlindPool::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");