eryon_rt/types/
capabilities.rs

1/*
2    Appellation: node_capabilities <module>
3    Contrib: @FL03
4*/
5
6/// Information about a node's capabilities and resource usage
7#[derive(Clone, Copy, Debug, Default, Eq, Hash, Ord, PartialEq, PartialOrd)]
8#[cfg_attr(
9    feature = "serde",
10    derive(serde_derive::Deserialize, serde_derive::Serialize)
11)]
12pub struct NodeCapabilities {
13    pub(crate) memory_usage: usize,
14    pub(crate) compute_capability: usize,
15    pub(crate) learning_capability: bool,
16    pub(crate) feature_count: usize,
17}
18
19impl NodeCapabilities {
20    /// Create a new instance of `NodeCapabilities`
21    pub fn new(
22        memory_usage: usize,
23        compute_capability: usize,
24        learning_capability: bool,
25        feature_count: usize,
26    ) -> Self {
27        Self {
28            compute_capability,
29            feature_count,
30            learning_capability,
31            memory_usage,
32        }
33    }
34    /// returns a copy of the computational capability of the node
35    pub const fn compute_capability(&self) -> usize {
36        self.compute_capability
37    }
38    /// returns a mutable reference to the computational capability of the node
39    pub const fn compute_capability_mut(&mut self) -> &mut usize {
40        &mut self.compute_capability
41    }
42    /// returns a copy of the feature count of the node
43    pub const fn feature_count(&self) -> usize {
44        self.feature_count
45    }
46    /// returns a mutable reference to the feature count of the node
47    pub const fn feature_count_mut(&mut self) -> &mut usize {
48        &mut self.feature_count
49    }
50    /// returns a copy of the learning capability of the node
51    pub const fn learning_capability(&self) -> bool {
52        self.learning_capability
53    }
54    /// returns a mutable reference to the learning capability of the node
55    pub const fn learning_capability_mut(&mut self) -> &mut bool {
56        &mut self.learning_capability
57    }
58    /// returns a copy of the memory usage of the node
59    pub const fn memory_usage(&self) -> usize {
60        self.memory_usage
61    }
62    /// returns a mutable reference to the memory usage of the node
63    pub const fn memory_usage_mut(&mut self) -> &mut usize {
64        &mut self.memory_usage
65    }
66    /// updates the computational capability of the node and returns a mutable reference to the
67    /// instance
68    pub fn set_compute_capability(&mut self, compute_capability: usize) -> &mut Self {
69        self.compute_capability = compute_capability;
70        self
71    }
72    /// updates the feature count of the node and returns a mutable reference to the instance
73    pub fn set_feature_count(&mut self, feature_count: usize) -> &mut Self {
74        self.feature_count = feature_count;
75        self
76    }
77    /// updates the learning capability of the node and returns a mutable reference to the instance
78    pub fn set_learning_capability(&mut self, learning_capability: bool) -> &mut Self {
79        self.learning_capability = learning_capability;
80        self
81    }
82    /// updates the memory usage of the node and returns a mutable reference to the instance
83    pub fn set_memory_usage(&mut self, memory_usage: usize) -> &mut Self {
84        self.memory_usage = memory_usage;
85        self
86    }
87    /// returns a copy of the memory usage of the node
88    pub fn with_compute_capability(self, compute_capability: usize) -> Self {
89        Self {
90            compute_capability,
91            ..self
92        }
93    }
94    /// returns a new instance with the given feature count
95    pub fn with_feature_count(self, feature_count: usize) -> Self {
96        Self {
97            feature_count,
98            ..self
99        }
100    }
101    /// returns a new instance with the given learning capability
102    pub fn with_learning_capability(self, learning_capability: bool) -> Self {
103        Self {
104            learning_capability,
105            ..self
106        }
107    }
108    /// returns a new instance with the given memory usage
109    pub fn with_memory_usage(self, memory_usage: usize) -> Self {
110        Self {
111            memory_usage,
112            ..self
113        }
114    }
115}