pub struct Pooled<T: ?Sized> { /* private fields */ }Expand description
A shared thread-safe reference-counting handle for a pooled object.
§Implications of reference counted handles
The handle can be used to access the pooled object.
This is a reference-counted handle that automatically removes the object when the handle is dropped. Dropping the handle is the only way to remove the object from the pool. This is a shared handle that only grants shared access to the object. No exclusive references can be created through this handle.
§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> Pooled<T>
impl<T: ?Sized> Pooled<T>
Sourcepub fn ptr(&self) -> NonNull<T>
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.
Sourcepub fn as_pin(&self) -> Pin<&T>
pub 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.
Sourcepub fn erase(self) -> Pooled<()>
pub fn erase(self) -> Pooled<()>
Erase the type information from this handle, converting it to Pooled<()>.
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.