pub struct RawPooledMut<T: ?Sized> { /* private fields */ }Expand description
A handle to a value stored in a super::RawBlindPool with exclusive ownership guarantees.
Unlike RawPooled<T>, this handle cannot be copied or cloned, ensuring that only one
handle can exist for each pool item. This enables safe removal methods that consume the
handle, preventing double-use bugs that could lead to undefined behavior.
The handle provides access to the stored value via a pointer, similar to RawPooled<T>,
but with the additional safety guarantee of exclusive ownership.
§Thread safety
When T is Sync, the handle is thread-safe and can be freely moved and shared between
threads, providing safe concurrent access to the underlying data.
When T is not Sync, the handle is single-threaded and cannot be moved between threads
or shared between threads, preventing unsafe access to non-thread-safe data.
Implementations§
Source§impl<T: ?Sized> RawPooledMut<T>
impl<T: ?Sized> RawPooledMut<T>
Sourcepub fn ptr(&self) -> NonNull<T>
pub fn ptr(&self) -> NonNull<T>
Returns a pointer to the inserted value.
This is the only way to access the value stored in the pool. The owner of the handle has
exclusive access to the value and may both read and write and may create both & shared
and &mut exclusive references to the item.
§Example
use blind_pool::RawBlindPool;
let mut pool = RawBlindPool::new();
let pooled_mut = pool.insert_mut(2.5159_f64);
// Read data back from the memory.
let value = *pooled_mut; // Safe deref access
assert_eq!(value, 2.5159);Sourcepub fn erase(self) -> RawPooledMut<()>
pub fn erase(self) -> RawPooledMut<()>
Erases the type information from this RawPooledMut<T> handle,
returning a RawPooledMut<()>.
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 handle remains functionally equivalent and can still be used to remove the item from the pool safely. The only change is the removal of the type information.
§Example
use blind_pool::RawBlindPool;
let mut pool = RawBlindPool::new();
let pooled_mut = pool.insert_mut("Test".to_string());
// Erase the type information.
let erased = pooled_mut.erase();
// Can still be removed safely.
pool.remove_mut(erased);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::RawBlindPool;
let mut pool = RawBlindPool::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::RawBlindPool;
let mut pool = RawBlindPool::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 handle to a shared handle.
This consumes the RawPooledMut<T> and returns a RawPooled<T> that can be copied
and cloned. Use this when you no longer need the exclusive ownership guarantees
and want to share the handle.
Note that after calling this method, you lose the safety guarantees of exclusive ownership and must use unsafe removal methods.
§Example
use blind_pool::RawBlindPool;
let mut pool = RawBlindPool::new();
let pooled_mut = pool.insert_mut("Test".to_string());
// Convert to shared handle.
let shared = pooled_mut.into_shared();
// Can now copy the handle.
let shared_copy = shared;
// But removal requires unsafe code again.
unsafe { pool.remove(&shared_copy) };Trait Implementations§
Source§impl<T: ?Sized> Debug for RawPooledMut<T>
impl<T: ?Sized> Debug for RawPooledMut<T>
Source§impl<T: ?Sized> Deref for RawPooledMut<T>
impl<T: ?Sized> Deref for RawPooledMut<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::RawBlindPool;
let mut pool = RawBlindPool::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 RawPooledMut<T>
impl<T: ?Sized> DerefMut for RawPooledMut<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::RawBlindPool;
let mut pool = RawBlindPool::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");