Newer
Older
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
// TODO: research if there's a better way
#![cfg(not(feature = "std"))]
use super::{Meter, Weight};
static mut METER: Meter = Meter {
used_weight: 0,
depth: 0,
};
pub fn start() {
unsafe {
if METER.depth == 0 {
METER.used_weight = 0;
}
METER.depth = METER.depth.saturating_add(1);
}
}
pub fn using(weight: Weight) {
unsafe {
METER.used_weight = METER.used_weight.saturating_add(weight);
}
}
pub fn finish() {
unsafe {
METER.depth.checked_sub(1).map_or_else(
|| {
debug_assert!(false);
0
},
|v| v,
);
}
}
pub fn used_weight() -> Weight {
unsafe { METER.used_weight }
}