pub struct LPooled<T>(/* private fields */)
where
T: IsoPoolable;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> LPooled<T>where
T: IsoPoolable,
impl<T> LPooled<T>where
T: IsoPoolable,
Sourcepub fn take() -> LPooled<T>
pub fn take() -> LPooled<T>
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> AsRef<T> for LPooled<T>where
T: IsoPoolable,
impl<T> AsRef<T> for LPooled<T>where
T: IsoPoolable,
Source§impl<T> Borrow<T> for LPooled<T>where
T: IsoPoolable,
impl<T> Borrow<T> for LPooled<T>where
T: IsoPoolable,
Source§impl<T> Default for LPooled<T>where
T: IsoPoolable,
impl<T> Default for LPooled<T>where
T: IsoPoolable,
Source§impl<T> Deref for LPooled<T>where
T: IsoPoolable,
impl<T> Deref for LPooled<T>where
T: IsoPoolable,
Source§impl<T> DerefMut for LPooled<T>where
T: IsoPoolable,
impl<T> DerefMut for LPooled<T>where
T: IsoPoolable,
Source§impl<'de, T> Deserialize<'de> for LPooled<T>where
T: IsoPoolable + DeserializeOwned + 'static,
Available on crate feature serde only.
impl<'de, T> Deserialize<'de> for LPooled<T>where
T: IsoPoolable + DeserializeOwned + 'static,
Available on crate feature
serde only.Source§fn deserialize<D>(
deserializer: D,
) -> Result<LPooled<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<LPooled<T>, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl<T> Drop for LPooled<T>where
T: IsoPoolable,
impl<T> Drop for LPooled<T>where
T: IsoPoolable,
Source§impl<T, E> Extend<E> for LPooled<T>where
T: IsoPoolable + Extend<E>,
impl<T, E> Extend<E> for LPooled<T>where
T: IsoPoolable + Extend<E>,
Source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = E>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = E>,
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> From<T> for LPooled<T>where
T: IsoPoolable,
impl<T> From<T> for LPooled<T>where
T: IsoPoolable,
Source§impl<T, E> FromIterator<E> for LPooled<T>where
T: IsoPoolable + Extend<E>,
impl<T, E> FromIterator<E> for LPooled<T>where
T: IsoPoolable + Extend<E>,
Source§impl<T> Ord for LPooled<T>where
T: Ord + IsoPoolable,
impl<T> Ord for LPooled<T>where
T: Ord + IsoPoolable,
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 for LPooled<T>where
T: PartialOrd + IsoPoolable,
impl<T> PartialOrd for LPooled<T>where
T: PartialOrd + IsoPoolable,
Source§impl<T> Serialize for LPooled<T>where
T: IsoPoolable + Serialize,
Available on crate feature serde only.
impl<T> Serialize for LPooled<T>where
T: IsoPoolable + Serialize,
Available on crate feature
serde only.Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
impl<T> Eq for LPooled<T>where
T: Eq + IsoPoolable,
impl<T> StructuralPartialEq for LPooled<T>where
T: IsoPoolable,
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> UnsafeUnpin for LPooled<T>where
T: UnsafeUnpin,
impl<T> UnwindSafe for LPooled<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<R> TryRngCore for Rwhere
R: TryRng,
impl<R> TryRngCore for Rwhere
R: TryRng,
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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.Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<R> RngExt for R
impl<R> RngExt for R
Source§fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
fn random<T>(&mut self) -> Twhere
StandardUniform: Distribution<T>,
Return a random value via the
StandardUniform distribution. Read moreSource§fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
fn random_iter<T>(self) -> Iter<StandardUniform, Self, T>
Source§fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
fn random_range<T, R>(&mut self, range: R) -> Twhere
T: SampleUniform,
R: SampleRange<T>,
Generate a random value in the given range. Read more
Source§fn random_bool(&mut self, p: f64) -> bool
fn random_bool(&mut self, p: f64) -> bool
Return a bool with a probability
p of being true. Read moreSource§fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
fn random_ratio(&mut self, numerator: u32, denominator: u32) -> bool
Return a bool with a probability of
numerator/denominator of being
true. Read moreSource§fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
fn sample<T, D>(&mut self, distr: D) -> Twhere
D: Distribution<T>,
Sample a new value, using the given distribution. Read more
Source§fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
fn sample_iter<T, D>(self, distr: D) -> Iter<D, Self, T>where
D: Distribution<T>,
Self: Sized,
Create an iterator that generates values using the given distribution. Read more
Source§impl<T> ToCompactString for Twhere
T: Display,
impl<T> ToCompactString for Twhere
T: Display,
Source§fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
fn try_to_compact_string(&self) -> Result<CompactString, ToCompactStringError>
Fallible version of
ToCompactString::to_compact_string() Read moreSource§fn to_compact_string(&self) -> CompactString
fn to_compact_string(&self) -> CompactString
Converts the given value to a
CompactString. Read moreSource§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.