Struct round_based::async_runtime::AsyncProtocol
source · [−]pub struct AsyncProtocol<SM, I, O, W = BlindWatcher> { /* private fields */ }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 encrypted, authenticated), then stream and sink must meet these assumptions (e.g. encrypt, authenticate messages)
Implementations
sourceimpl<SM, I, O> AsyncProtocol<SM, I, O, BlindWatcher>
impl<SM, I, O> AsyncProtocol<SM, I, O, BlindWatcher>
sourceimpl<SM, I, O, W> AsyncProtocol<SM, I, O, W>
impl<SM, I, O, W> AsyncProtocol<SM, I, O, W>
sourcepub fn set_watcher<WR>(self, watcher: WR) -> AsyncProtocol<SM, I, O, WR>
pub fn set_watcher<WR>(self, watcher: WR) -> AsyncProtocol<SM, I, O, WR>
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.
sourceimpl<SM, I, O, IErr, W> AsyncProtocol<SM, I, O, W> where
SM: StateMachine,
SM::Err: Send,
SM: Send + 'static,
I: Stream<Item = Result<Msg<SM::MessageBody>, IErr>> + FusedStream + Unpin,
O: Sink<Msg<SM::MessageBody>> + Unpin,
W: ProtocolWatcher<SM>,
impl<SM, I, O, IErr, W> AsyncProtocol<SM, I, O, W> where
SM: StateMachine,
SM::Err: Send,
SM: Send + 'static,
I: Stream<Item = Result<Msg<SM::MessageBody>, IErr>> + FusedStream + Unpin,
O: Sink<Msg<SM::MessageBody>> + Unpin,
W: ProtocolWatcher<SM>,
sourcepub fn state_machine_ref(&self) -> Result<&SM, Error<SM::Err, IErr, O::Error>>
pub fn state_machine_ref(&self) -> Result<&SM, Error<SM::Err, IErr, O::Error>>
Get a reference to the inner state machine.
This is useful in case where you want to call any of the state machine’s methods.
Note that this could return an error if the state machine is missing, and that could only happen if the task/thread that is running the proceed call panicked.
sourcepub fn into_state_machine(self) -> Result<SM, Error<SM::Err, IErr, O::Error>>
pub fn into_state_machine(self) -> Result<SM, Error<SM::Err, IErr, O::Error>>
Try to convert the protocol into the inner state machine.
Same as Self::state_machine_ref, but instead of returning a reference, it will
take ownership of self and return the state machine, this useful in case when
the protocol has been executed and you want to get the state machine back.
Auto Trait Implementations
impl<SM, I, O, W> RefUnwindSafe for AsyncProtocol<SM, I, O, W> where
I: RefUnwindSafe,
O: RefUnwindSafe,
SM: RefUnwindSafe,
W: RefUnwindSafe,
impl<SM, I, O, W> Send for AsyncProtocol<SM, I, O, W> where
I: Send,
O: Send,
SM: Send,
W: Send,
impl<SM, I, O, W> Sync for AsyncProtocol<SM, I, O, W> where
I: Sync,
O: Sync,
SM: Sync,
W: Sync,
impl<SM, I, O, W> Unpin for AsyncProtocol<SM, I, O, W> where
I: Unpin,
O: Unpin,
SM: Unpin,
W: Unpin,
impl<SM, I, O, W> UnwindSafe for AsyncProtocol<SM, I, O, W> where
I: UnwindSafe,
O: UnwindSafe,
SM: UnwindSafe,
W: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more