pub struct LPooled<T: IsoPoolable>(/* private fields */);Expand description
A zero-cost wrapper for thread-local pooled objects.
LPooled<T> automatically returns objects to the thread-local pool when dropped.
This is the recommended default for most use cases as it’s faster than GPooled.
§When to Use
- Default choice for pooling
- Objects created and dropped on the same thread
- Maximum performance is important
For producer-consumer patterns where one thread creates and other threads consume,
use GPooled instead.
§Example
use poolshark::local::LPooled;
use std::collections::HashMap;
fn process_request(data: &[(&str, i32)]) -> LPooled<HashMap<String, i32>> {
// will reuse dropped HashMaps
let mut map: LPooled<HashMap<String, i32>> = LPooled::take();
for (k, v) in data {
map.insert(k.to_string(), *v);
}
map
}§Behavior
- Minimal overhead: Same size as
Ton the stack, with thread-local lookup cost on drop and take - Thread-safe: Can be sent between threads (implements
Send + SyncifTdoes) - Drop behavior: Returns to the pool of whichever thread drops it
- Automatic: No manual pool management required
Implementations§
Source§impl<T: IsoPoolable> LPooled<T>
impl<T: IsoPoolable> LPooled<T>
Sourcepub fn take() -> Self
pub fn take() -> Self
Take an object from the pool, or create one if the pool is empty.
This is the same as Default::default.
Trait Implementations§
Source§impl<T: IsoPoolable> AsRef<T> for LPooled<T>
impl<T: IsoPoolable> AsRef<T> for LPooled<T>
Source§impl<T: IsoPoolable> Borrow<T> for LPooled<T>
impl<T: IsoPoolable> Borrow<T> for LPooled<T>
Source§impl<T: IsoPoolable> Default for LPooled<T>
impl<T: IsoPoolable> Default for LPooled<T>
Source§impl<T: IsoPoolable> Deref for LPooled<T>
impl<T: IsoPoolable> Deref for LPooled<T>
Source§impl<T: IsoPoolable> DerefMut for LPooled<T>
impl<T: IsoPoolable> DerefMut for LPooled<T>
Source§impl<'de, T: IsoPoolable + DeserializeOwned + 'static> Deserialize<'de> for LPooled<T>
Available on crate feature serde only.
impl<'de, T: IsoPoolable + DeserializeOwned + 'static> Deserialize<'de> for LPooled<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> Drop for LPooled<T>
impl<T: IsoPoolable> Drop for LPooled<T>
Source§impl<T: IsoPoolable + Extend<E>, E> Extend<E> for LPooled<T>
impl<T: IsoPoolable + Extend<E>, E> Extend<E> for LPooled<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: IsoPoolable> From<T> for LPooled<T>
impl<T: IsoPoolable> From<T> for LPooled<T>
Source§impl<T: IsoPoolable + Extend<E>, E> FromIterator<E> for LPooled<T>
impl<T: IsoPoolable + Extend<E>, E> FromIterator<E> for LPooled<T>
Source§fn from_iter<I: IntoIterator<Item = E>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = E>>(iter: I) -> Self
Creates a value from an iterator. Read more
Source§impl<T: Ord + IsoPoolable> Ord for LPooled<T>
impl<T: Ord + IsoPoolable> Ord for LPooled<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: PartialOrd + IsoPoolable> PartialOrd for LPooled<T>
impl<T: PartialOrd + IsoPoolable> PartialOrd for LPooled<T>
Source§impl<T: IsoPoolable + Serialize> Serialize for LPooled<T>
Available on crate feature serde only.
impl<T: IsoPoolable + Serialize> Serialize for LPooled<T>
Available on crate feature
serde only.impl<T: Eq + IsoPoolable> Eq for LPooled<T>
impl<T: IsoPoolable> StructuralPartialEq for LPooled<T>
Auto Trait Implementations§
impl<T> Freeze for LPooled<T>where
T: Freeze,
impl<T> RefUnwindSafe for LPooled<T>where
T: RefUnwindSafe,
impl<T> Send for LPooled<T>where
T: Send,
impl<T> Sync for LPooled<T>where
T: Sync,
impl<T> Unpin for LPooled<T>where
T: Unpin,
impl<T> UnwindSafe for LPooled<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.