1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
use super::sealed::IsSession;
use super::*;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Default)]
pub struct Done;
impl IsSession for Done {}
impl HasDual for Done {
type DualSession = Done;
}
impl Actionable for Done {
type NextAction = Self;
}
impl<N: Unary> Scoped<N> for Done {}
impl<P, N: Unary> Subst<P, N> for Done {
type Substituted = Done;
}
impl<P, N: Unary> Then<P, N> for Done
where
P: Lift<N>,
{
type Combined = P::Lifted;
}
impl<N: Unary, Level: Unary> Lift<N, Level> for Done {
type Lifted = Done;
}
#[cfg(test)]
mod tests {
#![allow(unused)]
#[test]
fn done_in_seq() {
use crate::prelude::*;
use crate::types::*;
type S = Session! {
loop {
call {
send String;
}
recv String;
break;
}
};
async fn serve<Tx, Rx>(chan: Chan<S, Tx, Rx>) -> Result<(), Box<dyn std::error::Error>>
where
Tx: std::marker::Send + Transmitter + Transmit<String>,
Rx: std::marker::Send + Receive<String>,
Tx::Error: std::error::Error,
Rx::Error: std::error::Error,
{
let chan = chan
.call(|chan| async move {
chan.send("Hello!".to_string()).await?.close();
Ok::<_, Box<dyn std::error::Error>>(())
})
.await?
.1
.unwrap();
let (_string, chan) = chan.recv().await?;
chan.close();
Ok(())
}
}
}