RawPooledMut

Struct RawPooledMut 

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

Source

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

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);
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::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);
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::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 String
Source

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

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

Source§

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

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

impl<T: ?Sized> Deref for RawPooledMut<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::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§

type Target = T

The resulting type after dereferencing.
Source§

impl<T: ?Sized> DerefMut for RawPooledMut<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::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");
Source§

impl<T: ?Sized + Sync> Send for RawPooledMut<T>

Source§

impl<T: ?Sized + Sync> Sync for RawPooledMut<T>

Auto Trait Implementations§

§

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

§

impl<T> RefUnwindSafe for RawPooledMut<T>
where T: RefUnwindSafe + ?Sized,

§

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

§

impl<T> UnwindSafe for RawPooledMut<T>
where T: RefUnwindSafe + ?Sized,

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.