Skip to main content

ReadPool

Struct ReadPool 

Source
pub struct ReadPool { /* private fields */ }
Expand description

A bounded pool of reader connections. Clones share one pool.

Implementations§

Source§

impl ReadPool

Source

pub fn from_opener( cap: usize, open: impl Fn() -> Result<Connection> + Send + Sync + 'static, ) -> Result<Self>

A pool whose readers come from open, called once now to check it works and again for each new reader. The pool enforces cap and the closed and wait rules; query_only and other reader setup are the opener’s job. Intended for tests that need a pool over a connection they build themselves. Use DbOptions::open_read_pool for a real database.

Source

pub fn get(&self) -> Result<PooledReadConnection>

Checks out an idle reader, opens a new one while under the cap, or waits for a return. Fails with DbError::ReadPoolClosed once the pool is closed, including while waiting. The wait has no bound; use Self::get_timeout to give up after a deadline.

Source

pub fn get_timeout( &self, timeout: Duration, ) -> Result<Option<PooledReadConnection>>

Self::get with a bounded wait. Returns Ok(Some(reader)) as soon as a reader is idle or can be opened under the cap, and Ok(None) if none frees up within timeout. A zero timeout never waits: it returns an idle or newly opened reader, or Ok(None). If the pool is closed, or closes while waiting, the result is DbError::ReadPoolClosed, never Ok(None). Opening a new reader is not bounded by timeout. A timeout too large for the clock waits in bounded slices until a reader frees up or the pool closes.

Source

pub fn close(&self)

Stops handing out readers and drops the idle ones now. A reader still checked out closes when it is returned. Calling it again does nothing.

Source

pub fn close_and_wait(&self, timeout: Duration) -> Result<()>

Self::close, then waits up to timeout for every checked-out reader to be returned. Ok(()) means every connection is closed and its database file released. Otherwise it returns DbError::ReadPoolCloseTimeout with the number still out. Do not call it while holding a reader from this pool: that reader cannot come back, so the call times out. A timeout too large for the clock waits in bounded slices until the readers return.

Source

pub fn capacity(&self) -> usize

Source

pub fn idle_len(&self) -> usize

Source

pub fn total_len(&self) -> usize

Trait Implementations§

Source§

impl Clone for ReadPool

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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.