Struct sqlx_core::common::StatementCache

source ·
pub struct StatementCache<T> { /* private fields */ }
Expand description

A cache for prepared statements. When full, the least recently used statement gets removed.

Implementations§

source§

impl<T> StatementCache<T>

source

pub fn new(capacity: usize) -> Self

Create a new cache with the given capacity.

source

pub fn get_mut(&mut self, k: &str) -> Option<&mut T>

Returns a mutable reference to the value corresponding to the given key in the cache, if any.

source

pub fn insert(&mut self, k: &str, v: T) -> Option<T>

Inserts a new statement to the cache, returning the least recently used statement id if the cache is full, or if inserting with an existing key, the replaced existing statement.

source

pub fn len(&self) -> usize

The number of statements in the cache.

source

pub fn remove_lru(&mut self) -> Option<T>

Removes the least recently used item from the cache.

source

pub fn clear(&mut self)

Clear all cached statements from the cache.

source

pub fn contains_key(&mut self, k: &str) -> bool

True if cache has a value for the given key.

source

pub fn capacity(&self) -> usize

Returns the maximum number of statements the cache can hold.

source

pub fn is_enabled(&self) -> bool

Returns true if the cache capacity is more than 0.

Trait Implementations§

source§

impl<T: Debug> Debug for StatementCache<T>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for StatementCache<T>

§

impl<T> RefUnwindSafe for StatementCache<T>
where T: RefUnwindSafe,

§

impl<T> Send for StatementCache<T>
where T: Send,

§

impl<T> Sync for StatementCache<T>
where T: Sync,

§

impl<T> Unpin for StatementCache<T>

§

impl<T> UnwindSafe for StatementCache<T>
where T: RefUnwindSafe,

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> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more