MultiSessionManager

Struct MultiSessionManager 

Source
pub struct MultiSessionManager<T: AsyncReadExt + AsyncWriteExt + Unpin + Send + 'static> { /* private fields */ }
Expand description

Manager for multiple async sessions with select capabilities.

This provides the core multi-session functionality, allowing you to:

  • Manage multiple sessions simultaneously
  • Wait for any session to match a pattern (expect_any)
  • Wait for all sessions to match patterns (expect_all)
  • Send to multiple sessions in parallel
  • Select on multiple sessions with different patterns per session

Implementations§

Source§

impl<T: AsyncReadExt + AsyncWriteExt + Unpin + Send + 'static> MultiSessionManager<T>

Source

pub fn new() -> Self

Create a new multi-session manager.

Source

pub const fn with_timeout(self, timeout: Duration) -> Self

Set the default timeout for operations.

Source

pub fn with_config(self, config: SessionConfig) -> Self

Set the default session configuration.

Source

pub fn add( &mut self, session: Session<T>, label: impl Into<String>, ) -> SessionId

Add an existing session to the manager.

Returns the assigned session ID.

Source

pub async fn remove(&mut self, id: SessionId) -> Option<Session<T>>

Remove a session from the manager.

Returns the session if it existed.

Source

pub fn len(&self) -> usize

Get the number of sessions.

Source

pub fn is_empty(&self) -> bool

Check if there are no sessions.

Source

pub fn session_ids(&self) -> Vec<SessionId>

Get all session IDs.

Source

pub async fn label(&self, id: SessionId) -> Option<String>

Get the label for a session.

Source

pub async fn is_active(&self, id: SessionId) -> bool

Check if a session is active.

Source

pub async fn set_active(&self, id: SessionId, active: bool)

Set a session’s active state.

Source

pub async fn active_ids(&self) -> Vec<SessionId>

Get active session IDs.

Source

pub async fn send(&self, id: SessionId, data: &[u8]) -> Result<()>

Send data to a specific session.

§Errors

Returns an error if the session doesn’t exist or the send fails.

Source

pub async fn send_line(&self, id: SessionId, line: &str) -> Result<()>

Send a line to a specific session.

§Errors

Returns an error if the session doesn’t exist or the send fails.

Source

pub async fn send_all(&self, data: &[u8]) -> Vec<SendResult>

Send data to all active sessions in parallel.

Returns results for each session.

Source

pub async fn expect( &self, id: SessionId, pattern: impl Into<Pattern>, ) -> Result<Match>

Expect a pattern on a specific session.

§Errors

Returns an error if the session doesn’t exist or expect fails.

Source

pub async fn expect_any( &self, pattern: impl Into<Pattern>, ) -> Result<SelectResult>

Wait for any session to match the given pattern.

Returns as soon as any session matches. This is the primary multi-session select operation, equivalent to TCL Expect’s multi-spawn expect.

§Errors

Returns an error if all sessions timeout or encounter errors.

Source

pub async fn expect_any_of(&self, patterns: &[Pattern]) -> Result<SelectResult>

Wait for any session to match any of the given patterns.

§Errors

Returns an error if all sessions timeout or encounter errors.

Source

pub async fn expect_all( &self, pattern: impl Into<Pattern>, ) -> Result<Vec<SelectResult>>

Wait for all sessions to match patterns.

Each session must match at least one pattern. Returns results for all sessions.

§Errors

Returns an error if any session fails to match.

Source

pub async fn expect_all_of( &self, patterns: &[Pattern], ) -> Result<Vec<SelectResult>>

Wait for all sessions to match any of the given patterns.

§Errors

Returns an error if any session fails.

Source

pub async fn with_session<F, R>(&self, id: SessionId, f: F) -> Result<R>
where F: FnOnce(&mut Session<T>) -> R,

Execute a closure on a specific session.

This provides direct access to the session for operations not covered by the manager’s API.

§Errors

Returns an error if the session doesn’t exist.

Source

pub async fn with_session_async<F, Fut, R>( &self, id: SessionId, f: F, ) -> Result<R>
where F: FnOnce(&mut Session<T>) -> Fut, Fut: Future<Output = R>,

Execute an async closure on a specific session.

§Errors

Returns an error if the session doesn’t exist.

Trait Implementations§

Source§

impl<T: AsyncReadExt + AsyncWriteExt + Unpin + Send + 'static> Debug for MultiSessionManager<T>

Source§

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

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

impl<T: AsyncReadExt + AsyncWriteExt + Unpin + Send + 'static> Default for MultiSessionManager<T>

Source§

fn default() -> Self

Returns the “default value” for a type. 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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