donet_core/
dcatomic.rs

1/*
2    This file is part of Donet.
3
4    Copyright © 2024-2025 Max Rodriguez <[email protected]>
5
6    Donet is free software; you can redistribute it and/or modify
7    it under the terms of the GNU Affero General Public License,
8    as published by the Free Software Foundation, either version 3
9    of the License, or (at your option) any later version.
10
11    Donet is distributed in the hope that it will be useful,
12    but WITHOUT ANY WARRANTY; without even the implied warranty of
13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    GNU Affero General Public License for more details.
15
16    You should have received a copy of the GNU Affero General Public
17    License along with Donet. If not, see <https://www.gnu.org/licenses/>.
18*/
19
20//! Data model for a DC Atomic Field, which represents a remote
21//! procedure call method of a Distributed Class.
22
23use crate::dcfield::DCField;
24use crate::dcparameter::DCParameter;
25use crate::hashgen::*;
26
27/// Represents an atomic field of a Distributed Class.
28/// This defines the interface to a DClass object, and is
29/// always implemented as a remote procedure call (RPC).
30#[derive(Debug)]
31pub struct DCAtomicField {
32    base_field: DCField,
33    elements: Vec<DCParameter>,
34}
35
36impl std::fmt::Display for DCAtomicField {
37    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
38        writeln!(f, "TODO")
39    }
40}
41
42impl LegacyDCHash for DCAtomicField {
43    fn generate_hash(&self, hashgen: &mut DCHashGenerator) {
44        self.base_field.generate_hash(hashgen);
45
46        hashgen.add_int(self.elements.len().try_into().unwrap());
47
48        for param in &self.elements {
49            param.generate_hash(hashgen);
50        }
51    }
52}
53
54impl DCAtomicField {
55    #[inline(always)]
56    pub fn get_num_elements(&self) -> usize {
57        self.elements.len()
58    }
59
60    #[inline(always)]
61    pub fn get_element(&self, index: usize) -> Option<&DCParameter> {
62        self.elements.get(index)
63    }
64}