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(Clone, Debug, Copy, PartialEq, Eq, Hash)]
pub enum Purity {
Pure,
Reads,
Writes,
ReadsWrites,
}
impl Purity {
pub fn can_call(&self, other: Purity) -> bool {
match self {
Purity::Pure => other == Purity::Pure,
Purity::Reads => other == Purity::Pure || other == Purity::Reads,
Purity::Writes => other == Purity::Pure || other == Purity::Writes,
Purity::ReadsWrites => true,
}
}
pub fn to_attribute_syntax(&self) -> String {
use crate::constants::*;
match self {
Purity::Pure => "".to_owned(),
Purity::Reads => STORAGE_PURITY_READ_NAME.to_owned(),
Purity::Writes => STORAGE_PURITY_WRITE_NAME.to_owned(),
Purity::ReadsWrites => {
format!("{STORAGE_PURITY_READ_NAME}, {STORAGE_PURITY_WRITE_NAME}")
}
}
}
}
impl Default for Purity {
fn default() -> Self {
Purity::Pure
}
}
pub fn promote_purity(from: Purity, to: Purity) -> Purity {
match (from, to) {
(Purity::Reads, Purity::Writes)
| (Purity::Writes, Purity::Reads)
| (Purity::ReadsWrites, _) => Purity::ReadsWrites,
_otherwise => to,
}
}