Skip to main content

Pooled

Struct Pooled 

Source
pub struct Pooled<M: Manage, X: Exchange<M>> { /* private fields */ }
Expand description

A connection checked out of the pool.

Derefs to the underlying connection. Returns itself to the pool on drop — unless it has been poisoned, in which case it is closed instead.

§Cancellation safety

This is the part that differs most from a readiness-based pool. With completion-based IO, dropping a future with an operation in flight does not unwind the operation: the kernel still owns the buffer and the peer’s response is still coming. compio keeps the buffer sound, but your protocol is now out of step — the next reader on this connection will see the tail of someone else’s response.

A connection cancelled mid-operation must therefore be destroyed, never reused. Wrap each operation in begin_op:

ⓘ
let op = conn.begin_op();
let n = conn.read(&mut buf).await?;   // if this await is cancelled…
op.complete_op();                     // …this never runs, and the conn is dropped

If you never cancel (no select!, no timeouts, no early return between submit and completion) you can skip it. Everyone believes that about their code right up until they add a timeout.

Implementations§

Source§

impl<M: Manage, X: Exchange<M>> Pooled<M, X>

Source

pub fn meta(&self) -> &SlotMeta

Lifecycle metadata: age, idle time, checkout count.

Source

pub fn poison(&self)

Marks this connection unusable. It is closed on drop instead of pooled.

Call this whenever you learn the connection is in an unknown state: a protocol error, a partial write, a response you could not parse.

Source

pub fn is_poisoned(&self) -> bool

True if poison has been called, directly or by a dropped OpGuard.

Source

pub fn begin_op(&self) -> OpGuard

Arms cancellation protection for one operation.

The returned guard poisons this connection when dropped, unless [OpGuard::complete] runs first. It borrows nothing from self, so the connection stays fully usable while the guard is alive.

Source

pub fn take(self) -> M::Connection

Removes the connection from the pool’s control and hands it to you.

The shard’s budget is freed immediately, so a replacement may be opened.

Trait Implementations§

Source§

impl<M: Manage, X: Exchange<M>> Debug for Pooled<M, X>

Source§

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

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

impl<M: Manage, X: Exchange<M>> Deref for Pooled<M, X>

Source§

type Target = <M as Manage>::Connection

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<M: Manage, X: Exchange<M>> DerefMut for Pooled<M, X>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<M: Manage, X: Exchange<M>> Drop for Pooled<M, X>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<M, X> !RefUnwindSafe for Pooled<M, X>

§

impl<M, X> !Send for Pooled<M, X>

§

impl<M, X> !Sync for Pooled<M, X>

§

impl<M, X> !UnwindSafe for Pooled<M, X>

§

impl<M, X> Freeze for Pooled<M, X>
where Option<Slot<<M as Manage>::Connection>>: Freeze, Rc<Shard<M>>: Freeze, Pool<M, X>: Freeze,

§

impl<M, X> Unpin for Pooled<M, X>
where Option<Slot<<M as Manage>::Connection>>: Unpin, Rc<Shard<M>>: Unpin, Pool<M, X>: Unpin,

§

impl<M, X> UnsafeUnpin for Pooled<M, X>
where Option<Slot<<M as Manage>::Connection>>: UnsafeUnpin, Rc<Shard<M>>: UnsafeUnpin, Pool<M, X>: UnsafeUnpin,

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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