pub struct GPooled<T: Poolable> { /* private fields */ }Expand description
A wrapper for globally pooled objects with cross-thread pool affinity.
GPooled<T> ensures objects always return to their origin pool, regardless of which
thread drops them. This is essential for producer-consumer patterns where one thread
creates objects and other threads consume them.
§When to Use
Use GPooled when:
- One thread primarily creates objects, other threads consume them
- You need objects to return to a specific pool
- You have a producer-consumer pattern across threads
Otherwise, prefer LPooled for better performance.
§Example
use poolshark::global::{Pool, GPooled};
use std::sync::LazyLock;
// Shared pool for cross-thread usage
static MESSAGES: LazyLock<Pool<String>> = LazyLock::new(|| Pool::new(1024, 4096));
fn producer() -> GPooled<String> {
let mut msg = MESSAGES.take();
msg.push_str("Hello from producer");
msg // Can be sent to consumer thread
}
fn consumer(msg: GPooled<String>) {
println!("{}", msg);
// Dropped here, returns to MESSAGES pool (not consumer's thread-local pool)
}§Behavior
- Pool affinity: Always returns to the pool it was created from
- Thread-safe: Can be sent between threads
- Overhead: One word (8 bytes on 64-bit) to store pool pointer
- Lock-free: Uses
crossbeamlock-free queues
Implementations§
Source§impl<T: IsoPoolable> GPooled<T>
impl<T: IsoPoolable> GPooled<T>
Source§impl<T: Poolable> GPooled<T>
impl<T: Poolable> GPooled<T>
Sourcepub fn orphan(t: T) -> Self
pub fn orphan(t: T) -> Self
Creates a GPooled that isn’t connected to any pool.
Useful for branches where you know a given Pooled will always be empty.
Trait Implementations§
Source§impl<T: IsoPoolable> Default for GPooled<T>
impl<T: IsoPoolable> Default for GPooled<T>
Source§impl<'de, T: Poolable + DeserializeOwned + 'static> Deserialize<'de> for GPooled<T>
Available on crate feature serde only.
impl<'de, T: Poolable + DeserializeOwned + 'static> Deserialize<'de> for GPooled<T>
Available on crate feature
serde only.Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T: IsoPoolable + Extend<E>, E> Extend<E> for GPooled<T>
impl<T: IsoPoolable + Extend<E>, E> Extend<E> for GPooled<T>
Source§fn extend<I: IntoIterator<Item = E>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = E>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
Source§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one)Extends a collection with exactly one element.
Source§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one)Reserves capacity in a collection for the given number of additional elements. Read more
Source§impl<T: Poolable + Ord> Ord for GPooled<T>
impl<T: Poolable + Ord> Ord for GPooled<T>
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<T: Poolable + PartialOrd> PartialOrd for GPooled<T>
impl<T: Poolable + PartialOrd> PartialOrd for GPooled<T>
Source§impl<T: Poolable> RawPoolable for GPooled<T>
impl<T: Poolable> RawPoolable for GPooled<T>
Source§fn empty(pool: WeakPool<Self>) -> Self
fn empty(pool: WeakPool<Self>) -> Self
allocate a new empty object and set it’s pool pointer to
poolSource§fn reset(&mut self)
fn reset(&mut self)
empty the collection and reset it to its default state so it
can be put back in the pool
Source§fn really_drop(self)
fn really_drop(self)
Actually drop the inner object, don’t put it back in the pool,
make sure you do not call both this method and the drop
implementation that puts the object back in the pool!
impl<T: Poolable + Eq> Eq for GPooled<T>
Auto Trait Implementations§
impl<T> Freeze for GPooled<T>where
T: Freeze,
impl<T> RefUnwindSafe for GPooled<T>where
T: RefUnwindSafe,
impl<T> Send for GPooled<T>where
T: Send,
impl<T> Sync for GPooled<T>
impl<T> Unpin for GPooled<T>where
T: Unpin,
impl<T> UnwindSafe for GPooled<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key and return true if they are equal.