RawPooledMut

Struct RawPooledMut 

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

A unique handle to an object in an object pool.

§Implications of raw handles

The handle can be used to access the pooled object, as well as to remove it from the pool when no longer needed.

This is a raw handle that requires manual lifetime management of the pooled objects.

  • Accessing the target object is only possible via unsafe code as the handle does not know when the pool has been dropped - the caller must guarantee the pool still exists.
  • You must explicitly remove the target object from the pool when it is no longer needed. If the handle is merely dropped, the object it references remains in the pool until the pool itself is dropped. This is a unique handle, guaranteeing that no other handles to the same object exist. You may create both shared and exclusive references to the object through this handle. The handle may also be converted to a shared handle via .into_shared(). The handle becomes invalid when the pool is dropped.

§Thread safety

The handle provides access to an object of type T, so its thread-safety characteristics are determined by the type of the object it references.

If the underlying object T is Send then the handle is Send. If the underlying object T is Sync then the handle is Sync.

Implementations§

Source§

impl<T: ?Sized> RawPooledMut<T>

Source

pub fn ptr(&self) -> NonNull<T>

Get a pointer to the target object.

All pooled objects are guaranteed to be pinned for their entire lifetime, so this pointer remains valid for as long as the object remains in the pool.

The object pool implementation does not keep any references to the pooled objects, so you have the option of using this pointer to create Rust references directly without fear of any conflicting references created by the pool.

Source

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

Transforms the unique handle into a shared handle that can be cloned as needed.

A shared handle does not support the creation of exclusive references to the target object.

§Thread Safety

The resulting shared handle will only be Send if T: Send + Sync. This is a stronger requirement than for unique handles, which only require T: Send.

Source

pub unsafe fn as_pin(&self) -> Pin<&T>

Borrows the target object as a pinned shared reference.

All pooled objects are guaranteed to be pinned for their entire lifetime.

§Safety

The caller must guarantee that the pool will remain alive for the duration the returned reference is used.

Source

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

Borrows the target object as a pinned exclusive reference.

All pooled objects are guaranteed to be pinned for their entire lifetime.

§Safety

The caller must guarantee that the pool will remain alive for the duration the returned reference is used.

Source

pub unsafe fn as_ref(&self) -> &T

Borrows the target object via shared reference.

§Safety

The caller must guarantee that the pool remains alive for the duration the returned reference is used.

Source

pub fn erase(self) -> RawPooledMut<()>

Erase the type information from this handle, converting it to RawPooledMut<()>.

This is useful for extending the lifetime of an object in the pool without retaining type information. The type-erased handle prevents access to the object but ensures it remains in the pool.

Source§

impl<T: ?Sized + Unpin> RawPooledMut<T>

Source

pub unsafe fn as_mut(&mut self) -> &mut T

Borrows the target object as an exclusive reference.

§Safety

The caller must guarantee that the pool will remain alive for the duration the returned reference is used.

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> From<RawPooledMut<T>> for RawPooled<T>

Source§

fn from(value: RawPooledMut<T>) -> Self

Converts to this type from the input type.

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<T> Sync for RawPooledMut<T>
where T: ?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<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.