N-ary Choice

macro define_choice! {
  $choice ;
  $label1: $protocol1,
  $label2: $protocol2,
  ...
}
  • Define N branches of labeled choices

  • Choices are in the form { L0: A0, L1: A1, ... } are desugard into HList![A0, A1, ...].

  • Labeled are defined as type aliases to prisms, e.g.

    type L0 = Z;
    type L1 = S<Z>;
    ...
    

Example: Either

define_choice! { Either<A, B>;
  Left: A,
  Right: B,
}

Example

define_choice! { MyChoices;
  Foo: ReceiveValue<String, End>,
  Bar: SendValue<u64, End>,
  Baz: End,
}