cbtop/grammar/
resources.rs1#[derive(Debug, Clone, PartialEq)]
5pub enum ScaleBinding {
6 ProblemSize,
8 DataVolume,
10 Throughput,
12 Custom(String),
14}
15
16#[derive(Debug, Clone, Copy, PartialEq, Eq)]
18pub struct ByteSize(pub usize);
19
20impl ByteSize {
21 pub fn mb(mb: usize) -> Self {
23 ByteSize(mb * 1024 * 1024)
24 }
25
26 pub fn gb(gb: usize) -> Self {
28 ByteSize(gb * 1024 * 1024 * 1024)
29 }
30
31 pub fn bytes(&self) -> usize {
33 self.0
34 }
35}
36
37#[derive(Debug, Clone, PartialEq, Default)]
39pub struct ResourceMapping {
40 pub cores: Option<ScaleBinding>,
42 pub memory: Option<ScaleBinding>,
44 pub bandwidth: Option<ScaleBinding>,
46 pub latency: Option<ScaleBinding>,
48 pub cores_value: Option<usize>,
50 pub memory_value: Option<ByteSize>,
52}
53
54impl ResourceMapping {
55 pub fn new() -> Self {
57 Self::default()
58 }
59
60 pub fn cores(mut self, binding: ScaleBinding) -> Self {
62 self.cores = Some(binding);
63 self
64 }
65
66 pub fn cores_value(mut self, count: usize) -> Self {
68 self.cores_value = Some(count);
69 self
70 }
71
72 pub fn memory(mut self, binding: ScaleBinding) -> Self {
74 self.memory = Some(binding);
75 self
76 }
77
78 pub fn memory_value(mut self, size: ByteSize) -> Self {
80 self.memory_value = Some(size);
81 self
82 }
83}