Struct round_based::async_runtime::AsyncProtocol[][src]

pub struct AsyncProtocol<SM, I, O, W = BlindWatcher> { /* fields omitted */ }
This is supported on crate feature async-runtime only.
Expand description

Executes protocol in async environment using tokio backend

In the most simple setting, you just provide protocol initial state, stream of incoming messages, and sink for outgoing messages, and you’re able to easily execute it:

fn incoming() -> impl Stream<Item=Result<Msg<M>, Error>> + FusedStream + Unpin {
    // ...
}
fn outgoing() -> impl Sink<Msg<M>, Error=Error> + Unpin {
    // ...
}
let output: State::Output = AsyncProtocol::new(State::initial(), incoming(), outgoing())
    .run().await?;
// ...

Note that if the protocol has some cryptographical assumptions on transport channel (e.g. messages should be ecrypted, authenticated), then stream and sink must meet these assumptions (e.g. encrypt, authenticate messages)

Implementations

Constructs new protocol executor from initial state, channels of incoming and outgoing messages

Sets new protocol watcher

Protocol watcher looks after protocol execution. See list of observable events in ProtocolWatcher trait.

Default watcher: BlindWatcher that does nothing with received events. For development purposes it’s convenient to pick StderrWatcher.

Executes the protocol

Returns protocol output or first occurred critical error

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.