Skip to main content

Pool

Struct Pool 

Source
pub struct Pool<T> {
    idle: Vec<Idle<T>>,
    max_per_key: usize,
    max_total: usize,
    idle_ms: u64,
}
Expand description

待っている接続の置き場。

Fields§

§idle: Vec<Idle<T>>§max_per_key: usize§max_total: usize§idle_ms: u64

Implementations§

Source§

impl<T> Pool<T>

Source

pub const fn new(max_per_key: usize, max_total: usize, idle_ms: u64) -> Self

max_per_key: 相手 1 つあたりの上限。max_total: 全体の上限。idle_ms: これより長く待った接続は使わない。

Source

pub fn len(&self) -> usize

待っている接続の数。

Source

pub fn is_empty(&self) -> bool

待っている接続が無いか。

Source

fn expire(&mut self, now_ms: u64, dropped: &mut Vec<T>)

待ちすぎた接続(相手を問わない)を dropped へ移す。

Source

pub fn checkout( &mut self, key: &str, now_ms: u64, dropped: &mut Vec<T>, ) -> Option<T>

key の相手への接続を 1 本取り出す。一番新しく置いた物を渡す(相手が先に閉じている見込みが一番低い)。 待ちすぎた接続は dropped へ移す。生きているかどうかは呼ぶ側が確かめる。

Source

pub fn checkin(&mut self, key: &str, conn: T, now_ms: u64, dropped: &mut Vec<T>)

使い終わった接続を置く。上限を超えるぶんは古い物から dropped へ移す (上限が 0 なら、渡された接続そのものを dropped へ移す)。

Source

pub fn drain(&mut self, dropped: &mut Vec<T>)

全部を dropped へ移す(ネットワークの作り直しのとき用)。

Auto Trait Implementations§

§

impl<T> Freeze for Pool<T>

§

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

§

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

§

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

§

impl<T> Unpin for Pool<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Pool<T>

§

impl<T> UnwindSafe for Pool<T>
where T: 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> 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> Same for T

Source§

type Output = T

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