Skip to main content

Connection

Struct Connection 

Source
pub struct Connection<'b, S, TX, TS, D = NoDelay> { /* private fields */ }
Expand description

An active Modbus TCP → RTU bridge connection.

Returned by Bridge::accept. Mutably borrows the bridge for its lifetime, preventing a second connection from being accepted until this one is finished.

Drive the connection by calling next in a loop.

Implementations§

Source§

impl<'b, S, TX, TS, D> Connection<'b, S, TX, TS, D>

Source

pub fn into_stream(self) -> TS

Consumes the connection and returns the underlying TCP stream.

§Examples
let socket = conn.into_stream();
socket.close();
Source§

impl<S, TX, TS> Connection<'_, S, TX, TS, NoDelay>
where S: Read + Write, TX: OutputPin, TS: Read + Write,

Source

pub async fn next( &mut self, ) -> Result<BridgeEvent, BridgeError<S::Error, TS::Error>>

Drives one complete Modbus request/response cycle asynchronously.

§Errors

Returns BridgeError::TcpClosed when the TCP client closes the connection cleanly.

Source§

impl<S, TX, TS, D> Connection<'_, S, TX, TS, D>
where S: Read + Write, TX: OutputPin, TS: Read + Write, D: DelayNs,

Source

pub async fn next( &mut self, ) -> Result<BridgeEvent, BridgeError<S::Error, TS::Error>>

Drives one complete Modbus request/response cycle asynchronously, with timeouts.

Applies tcp_timeout_ms around reading the incoming TCP request and rtu_timeout_ms around the RTU send+receive cycle.

§Errors

Returns BridgeError::Timeout if a deadline expires.

Auto Trait Implementations§

§

impl<'b, S, TX, TS, D> Freeze for Connection<'b, S, TX, TS, D>
where TS: Freeze,

§

impl<'b, S, TX, TS, D> RefUnwindSafe for Connection<'b, S, TX, TS, D>

§

impl<'b, S, TX, TS, D> Send for Connection<'b, S, TX, TS, D>
where TS: Send, D: Send, S: Send, TX: Send,

§

impl<'b, S, TX, TS, D> Sync for Connection<'b, S, TX, TS, D>
where TS: Sync, D: Sync, S: Sync, TX: Sync,

§

impl<'b, S, TX, TS, D> Unpin for Connection<'b, S, TX, TS, D>
where TS: Unpin,

§

impl<'b, S, TX, TS, D> UnsafeUnpin for Connection<'b, S, TX, TS, D>
where TS: UnsafeUnpin,

§

impl<'b, S, TX, TS, D = NoDelay> !UnwindSafe for Connection<'b, S, TX, TS, D>

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.