Skip to main content

BridgeBuilder

Struct BridgeBuilder 

Source
pub struct BridgeBuilder<S, TX, D = NoDelay> { /* private fields */ }
Expand description

Builder for Bridge. Obtain via Bridge::builder().

Uses a typestate pattern: S and TX start as () and are replaced when .rtu() is called, preventing .build() before the serial port is supplied. D starts as NoDelay and can be upgraded with .delay().

Implementations§

Source§

impl BridgeBuilder<(), (), NoDelay>

Source

pub fn new() -> Self

Creates a new BridgeBuilder with no serial port configured.

Prefer Bridge::builder() over calling this directly.

Source§

impl<D> BridgeBuilder<(), (), D>

Source

pub fn rtu<S, TX>(self, serial: S, tx_en: TX) -> BridgeBuilder<S, TX, D>

Supplies the serial port and RS-485 TX-enable pin.

§Examples
let bridge = Bridge::builder()
    .rtu(uart, tx_en_pin)
    .build();
Source

pub fn rtu_no_pin<S>(self, serial: S) -> BridgeBuilder<S, NoPin, D>

Supplies the serial port without a TX-enable pin.

Use this when the RS-485 transceiver handles direction control automatically.

§Examples
let bridge = Bridge::builder()
    .rtu_no_pin(uart)
    .build();
Source§

impl<S, TX, D> BridgeBuilder<S, TX, D>

Source

pub fn rtu_timeout(self, ms: u32) -> Self

Sets the RTU I/O timeout in milliseconds.

Applied while waiting for the RTU device response in each cycle. Requires a delay provider — call .delay() as well.

Source

pub fn tcp_timeout(self, ms: u32) -> Self

Sets the TCP I/O timeout in milliseconds.

Applied while waiting for an incoming TCP request in each cycle. Requires a delay provider — call .delay() as well.

Source

pub fn build(self) -> Bridge<S, TX, D>

Builds and returns the configured Bridge.

§Examples
let mut bridge = Bridge::builder()
    .rtu(uart, tx_en)
    .build();
Source§

impl<S, TX> BridgeBuilder<S, TX, NoDelay>

Source

pub fn delay<D2>(self, delay: D2) -> BridgeBuilder<S, TX, D2>

Supplies a delay provider and upgrades D from NoDelay.

Must be called before .build() when using .rtu_timeout() or .tcp_timeout().

§Examples
let bridge = Bridge::builder()
    .rtu(uart, pin)
    .rtu_timeout(500)
    .delay(my_timer)
    .build();

Trait Implementations§

Source§

impl Default for BridgeBuilder<(), (), NoDelay>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<S, TX, D> Freeze for BridgeBuilder<S, TX, D>
where S: Freeze, TX: Freeze, D: Freeze,

§

impl<S, TX, D> RefUnwindSafe for BridgeBuilder<S, TX, D>

§

impl<S, TX, D> Send for BridgeBuilder<S, TX, D>
where S: Send, TX: Send, D: Send,

§

impl<S, TX, D> Sync for BridgeBuilder<S, TX, D>
where S: Sync, TX: Sync, D: Sync,

§

impl<S, TX, D> Unpin for BridgeBuilder<S, TX, D>
where S: Unpin, TX: Unpin, D: Unpin,

§

impl<S, TX, D> UnsafeUnpin for BridgeBuilder<S, TX, D>

§

impl<S, TX, D> UnwindSafe for BridgeBuilder<S, TX, D>
where S: UnwindSafe, TX: UnwindSafe, D: 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, 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.