Struct regex_automata::util::pool::inner::PoolGuard

source ·
pub(super) struct PoolGuard<'a, T: Send, F: Fn() -> T> {
    pool: &'a Pool<T, F>,
    value: Result<Box<T>, usize>,
    discard: bool,
}
Expand description

A guard that is returned when a caller requests a value from the pool.

Fields§

§pool: &'a Pool<T, F>

The pool that this guard is attached to.

§value: Result<Box<T>, usize>

This is Err when the guard represents the special “owned” value. In which case, the value is retrieved from ‘pool.owner_val’. And in the special case of Err(THREAD_ID_DROPPED), it means the guard has been put back into the pool and should no longer be used.

§discard: bool

When true, the value should be discarded instead of being pushed back into the pool. We tend to use this under high contention, and this allows us to avoid inflating the size of the pool. (Because under contention, we tend to create more values instead of waiting for access to a stack of existing values.)

Implementations§

source§

impl<'a, T: Send, F: Fn() -> T> PoolGuard<'a, T, F>

source

pub(super) fn value(&self) -> &T

Return the underlying value.

source

pub(super) fn value_mut(&mut self) -> &mut T

Return the underlying value as a mutable borrow.

source

pub(super) fn put(this: PoolGuard<'_, T, F>)

Consumes this guard and puts it back into the pool.

source

fn put_imp(&mut self)

Puts this guard back into the pool by only borrowing the guard as mutable. This should be called at most once.

Trait Implementations§

source§

impl<'a, T: Send + Debug, F: Fn() -> T> Debug for PoolGuard<'a, T, F>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'a, T: Send, F: Fn() -> T> Drop for PoolGuard<'a, T, F>

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<'a, T, F> Freeze for PoolGuard<'a, T, F>

§

impl<'a, T, F> RefUnwindSafe for PoolGuard<'a, T, F>

§

impl<'a, T, F> Send for PoolGuard<'a, T, F>
where F: Send + Sync,

§

impl<'a, T, F> Sync for PoolGuard<'a, T, F>
where F: Send + Sync, T: Sync,

§

impl<'a, T, F> Unpin for PoolGuard<'a, T, F>

§

impl<'a, T, F> UnwindSafe for PoolGuard<'a, T, F>

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>,

§

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>,

§

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.