Skip to main content

SessionSet

Struct SessionSet 

Source
pub struct SessionSet<K, S> { /* private fields */ }
Expand description

A keyed collection of sessions driven as one.

K is whatever identifies a peer to the application: a node id, a serial number, a database row id. The set never interprets it.

Implementations§

Source§

impl<K: Ord, S: Session> SessionSet<K, S>

Source

pub fn new() -> Self

An empty set.

Source

pub fn insert(&mut self, key: K, session: S) -> Option<S>

Add a session, returning whatever was under that key.

Source

pub fn remove(&mut self, key: &K) -> Option<S>

Take a session out — when its transport has gone, for instance.

Source

pub fn get(&self, key: &K) -> Option<&S>

One session.

Source

pub fn get_mut(&mut self, key: &K) -> Option<&mut S>

One session, mutably, to feed a frame into.

Source

pub fn len(&self) -> usize

How many sessions there are.

Source

pub fn is_empty(&self) -> bool

Whether there are none.

Source

pub fn iter(&self) -> impl Iterator<Item = (&K, &S)>

Every session, in key order.

Source

pub fn iter_mut(&mut self) -> impl Iterator<Item = (&K, &mut S)>

Every session, mutably, in key order.

Source

pub fn open_all(&mut self, now: Timestamp)

Open every session that has not been opened.

Source

pub fn poll_timeout(&self) -> Option<Timestamp>

The soonest deadline across the whole set.

This is the number an event loop sleeps on. A set of a thousand sessions still has exactly one timer.

Source

pub fn next_deadline(&self) -> Option<(&K, Timestamp)>

Which session owns the soonest deadline, for a caller that would rather wake one session than sweep them all.

Source

pub fn handle_timeout(&mut self, now: Timestamp)

Fire every deadline that has come due.

Sweeping the whole set rather than only the session that woke us is deliberate: several deadlines commonly fall in the same millisecond, and a loop that handles one per wake-up turns a burst into a long tail of timer round-trips.

Source

pub fn drain_transmit(&mut self) -> Vec<(K, Outgoing)>
where K: Clone,

Everything every session wants to send, tagged with whose it is.

The key is cloned, not borrowed. Draining and then acting on what was drained is the only thing a caller does with the result — write the frame to the socket it looks up by that key, close the session that just emitted it, remove one whose transport has gone — and a borrowed key would hold the set immutably for exactly as long as the result lives.

Source

pub fn drain_events(&mut self) -> Vec<(K, S::Event)>
where K: Clone,

Everything every session wants to tell the application, tagged with whose it is.

Cloned for the same reason drain_transmit clones: acting on an event usually means touching the set the event came from.

Source

pub fn retain_open(&mut self) -> usize

Drop every session whose state machine has finished.

A set that is never pruned is a memory leak with extra steps: a reconnecting device produces a new session each time, and the closed ones have nothing left to say.

Source

pub fn close_all(&mut self)

Close every session.

Trait Implementations§

Source§

impl<K: Debug, S: Debug> Debug for SessionSet<K, S>

Source§

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

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

impl<K: Default, S: Default> Default for SessionSet<K, S>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<K, S> Forget for SessionSet<K, S>

§

impl<K, S> Freeze for SessionSet<K, S>
where BTreeMap<K, S>: Freeze,

§

impl<K, S> RefUnwindSafe for SessionSet<K, S>
where BTreeMap<K, S>: RefUnwindSafe,

§

impl<K, S> Send for SessionSet<K, S>
where BTreeMap<K, S>: Send,

§

impl<K, S> Sync for SessionSet<K, S>
where BTreeMap<K, S>: Sync,

§

impl<K, S> Unpin for SessionSet<K, S>
where BTreeMap<K, S>: Unpin,

§

impl<K, S> UnsafeUnpin for SessionSet<K, S>
where BTreeMap<K, S>: UnsafeUnpin,

§

impl<K, S> UnwindSafe for SessionSet<K, S>
where BTreeMap<K, S>: 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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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