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
|
#[derive(Debug)]
enum StatusCode {
Ok,
}
#[derive(Debug)]
struct Mailbox {
messages: Vec<Message>,
}
type Message = String;
#[derive(Debug)]
struct CubeSat {
id: u64,
mailbox: Mailbox,
}
impl CubeSat {
fn recv(&mut self) -> Option<Message> {
self.mailbox.messages.pop()
}
}
struct GroundStation;
impl GroundStation {
fn send(&self, to: &mut CubeSat, msg: Message) {
to.mailbox.messages.push(msg);
}
}
fn main() {
let base = GroundStation {};
let mut sat_a = CubeSat { id: 0, mailbox: Mailbox { messages: vec![] } };
let mut sat_b = CubeSat { id: 1, mailbox: Mailbox { messages: vec![] } };
let mut sat_c = CubeSat { id: 2, mailbox: Mailbox { messages: vec![] } };
println!("t0: {:?}", sat_a);
// sat_a.mailbox.messages.push(Message::from("hi"));
base.send(&mut sat_a, Message::from("hello there!"));
println!("t1: {:?}", sat_a);
let msg = sat_a.recv();
//println!("{:?}", msg);
println!("t2: {:?}", sat_a);
}
|