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
use crate::vcell::VCell;
pub trait Reg {
type Val: Copy;
fn access_with<F, R>(&self, f: F) -> R
where
F: Fn(&VCell<Self::Val>) -> R;
}
pub trait ReadReg: Reg {
type Read: From<Self::Val>;
fn read(&self) -> Self::Read {
let v = self.access_with(|vc| vc.get());
v.into()
}
}
pub trait WriteReg: Reg {
type Write: Into<Self::Val>;
fn write(&self, w: Self::Write) {
let v = w.into();
self.access_with(|vc| vc.set(v));
}
}