#[read]
Expand description
Macro deriving a ReadState
implementation for the destination state type,
consuming a message of message_type
and the current state, as indicated by
the transition tuple.
Example:
ⓘ
#[hax_lib_protocol_macros::read(A1, A2, Message)]
fn read_pong(_state: A1, msg: Message) -> ::hax_lib_protocol::ProtocolResult<A2> {
match msg {
Message::Ping(_) => Err(::hax_lib_protocol::ProtocolError::InvalidMessage),
Message::Pong(received) => Ok(A2 { received }),
}
}
// The following is generated by the macro:
#[hax_lib::exclude]
impl TryFrom<(A1, Message)> for A2 {
type Error = ::hax_lib_protocol::ProtocolError;
fn try_from((state, msg): (A1, Message)) -> Result<Self, Self::Error> {
read_pong(state, msg)
}
}
#[hax_lib::exclude]
impl ReadState<A2> for A1 {
type Message = Message;
fn read(self, msg: Message) -> ::hax_lib_protocol::ProtocolResult<A2> {
A2::try_from((self, msg))
}
}