Attribute Macro write

Source
#[write]
Expand description

Macro deriving a WriteState implementation for the origin state type, generating a message of message_type and a new state, as indicated by the transition tuple.

Example:

#[hax_lib_protocol_macros::write(A0, A1, Message)]
fn write_ping(state: A0) -> ::hax_lib_protocol::ProtocolResult<(A1, Message)> {
   Ok((A1 {}, Message::Ping(state.data)))
}

// The following is generated by the macro:
#[hax_lib::exclude]
impl TryFrom<A0> for (A1, Message) {
   type Error = ::hax_lib_protocol::ProtocolError;

   fn try_from(value: A0) -> Result<Self, Self::Error> {
      write_ping(value)
   }
}

#[hax_lib::exclude]
impl WriteState for A0 {
   type NextState = A1;
   type Message = Message;

   fn write(self) -> ::hax_lib_protocol::ProtocolResult<(Self::NextState, Message)> {
       self.try_into()
   }
}