Macro session_types::offer
[−]
[src]
macro_rules! offer { ( $id:ident, $branch:ident => $code:expr, $($t:tt)+ ) => { ... }; ( $id:ident, $branch:ident => $code:expr ) => { ... }; }
This macro is convenient for server-like protocols of the form:
Offer<A, Offer<B, Offer<C, ... >>>
Examples
Assume we have a protocol Offer<Recv<u64, Eps>, Offer<Recv<String, Eps>,Eps>>>
we can use the offer!
macro as follows:
#[macro_use] extern crate session_types; use session_types::*; use std::thread::spawn; fn srv(c: Chan<(), Offer<Recv<u64, Eps>, Offer<Recv<String, Eps>, Eps>>>) { offer! { c, Number => { let (c, n) = c.recv(); assert_eq!(42, n); c.close(); }, String => { c.recv().0.close(); }, Quit => { c.close(); } } } fn cli(c: Chan<(), Choose<Send<u64, Eps>, Choose<Send<String, Eps>, Eps>>>) { c.sel1().send(42).close(); } fn main() { let (s, c) = session_channel(); spawn(move|| cli(c)); srv(s); }
The identifiers on the left-hand side of the arrows have no semantic meaning, they only provide a meaningful name for the reader.