ferrite_session/internal/protocol/choice/
either.rs

1use std::marker::PhantomData;
2
3use crate::internal::functional::{
4  nat::*,
5  row::*,
6};
7
8pub struct Either<A, B>
9{
10  phantom: PhantomData<(A, B)>,
11}
12
13impl<A, B> ToRow for Either<A, B>
14{
15  type Row = (A, (B, ()));
16}
17
18pub type EitherRow<A, B> = Sum<A, Sum<B, Bottom>>;
19
20#[allow(non_upper_case_globals)]
21pub const LeftLabel: ChoiceSelector<Z> = <ChoiceSelector<Z>>::new();
22
23#[allow(non_upper_case_globals)]
24pub const RightLabel: ChoiceSelector<S<Z>> = <ChoiceSelector<S<Z>>>::new();
25
26pub enum EitherChoice<A, B>
27{
28  Left(A),
29  Right(B),
30}
31
32pub use EitherChoice::{
33  Left,
34  Right,
35};
36
37impl<A, B> From<Sum<A, Sum<B, Bottom>>> for EitherChoice<A, B>
38{
39  fn from(row: Sum<A, Sum<B, Bottom>>) -> EitherChoice<A, B>
40  {
41    match row {
42      Sum::Inl(a) => Left(a),
43      Sum::Inr(Sum::Inl(b)) => Right(b),
44      Sum::Inr(Sum::Inr(bot)) => match bot {},
45    }
46  }
47}