Skip to main content

Pool

Struct Pool 

Source
pub struct Pool<DB>(/* private fields */);
Expand description

The pool a handler queries through: writes through it commit on their own, whatever the delivery’s outcome.

It reads PoolContext, which every delivery of an InboxQueue subscription lends, or TxContext after Ctx<keys::Tx<..>>. On the app’s runtime it yields the service’s pool. On a dedicated thread it yields the thread’s own pool, built from the service pool’s options on the first read there. Its connections open on the thread and close with it, so none outlives the thread’s runtime in the service’s pool. It opens one connection at most, or the number InboxThreads::connections sets. A read costs one thread-local access and one clone of a pool handle. A pool’s type names its database, and so does the key: keys::Pool<Postgres>.

§Examples

use ruststream_sqlx::prelude::*;
use sqlx::Postgres;

#[subscriber(InboxQueue::<Job>::new("visits"))]
async fn count(visit: &Visit, Ctx(pool): Ctx<keys::Pool<Postgres>>) -> HandlerOutcome {
    let counted = sqlx::query("UPDATE pages SET visits = visits + 1 WHERE path = $1")
        .bind(&visit.page)
        .execute(&pool)
        .await;
    if counted.is_ok() { HandlerOutcome::ack() } else { HandlerOutcome::retry() }
}

Trait Implementations§

Source§

impl<DB> Clone for Pool<DB>

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
Source§

impl<DB: QueueDatabase> ContextField for Pool<DB>

Source§

type Context = PoolContext<DB>

The per-delivery context type this key reads from.
Source§

type Value = Pool<DB>

The owned value the key yields.
Source§

fn read(self, src: &PoolContext<DB>) -> DbPool<DB>

Reads this key’s field out of src. Named apart from Field::get so a key implementing both traits stays unambiguous to call.
Source§

impl<DB> Copy for Pool<DB>

Source§

impl<DB> Debug for Pool<DB>

Source§

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

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

impl<DB> Default for Pool<DB>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<DB> Freeze for Pool<DB>
where PhantomData<fn() -> DB>: Freeze,

§

impl<DB> RefUnwindSafe for Pool<DB>
where PhantomData<fn() -> DB>: RefUnwindSafe,

§

impl<DB> Send for Pool<DB>
where PhantomData<fn() -> DB>: Send,

§

impl<DB> Sync for Pool<DB>
where PhantomData<fn() -> DB>: Sync,

§

impl<DB> Unpin for Pool<DB>
where PhantomData<fn() -> DB>: Unpin,

§

impl<DB> UnsafeUnpin for Pool<DB>
where PhantomData<fn() -> DB>: UnsafeUnpin,

§

impl<DB> UnwindSafe for Pool<DB>
where PhantomData<fn() -> DB>: UnwindSafe,

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<K> CtxKey for K
where K: ContextField,

Source§

type Value = <K as ContextField>::Value

The owned value the extractor binds.
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, W> HasTypeWitness<W> for T
where W: MakeTypeWitness<Arg = T>, T: ?Sized,

Source§

const WITNESS: W = W::MAKE

A constant of the type witness
Source§

impl<T> Identity for T
where T: ?Sized,

Source§

const TYPE_EQ: TypeEq<T, <T as Identity>::Type> = TypeEq::NEW

Proof that Self is the same type as Self::Type, provides methods for casting between Self and Self::Type.
Source§

type Type = T

The same type as Self, used to emulate type equality bounds (T == U) with associated type equality constraints (T: Identity<Type = U>).
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> PublishedThrough<DefaultSlot> for T

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
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