donet_core/
dcparameter.rs

1/*
2    This file is part of Donet.
3
4    Copyright © 2024 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 that represents a single parameter of an atomic
21//! field, which together form a RPC method signature.
22
23use crate::dcatomic::DCAtomicField;
24use crate::dctype::DCTypeDefinition;
25use crate::hashgen::*;
26
27/// Represents the type specification of a parameter within an atomic field.
28#[derive(Debug)]
29pub struct DCParameter<'dc> {
30    parent: &'dc DCAtomicField<'dc>,
31    base_type: DCTypeDefinition,
32    identifier: Option<String>,
33    type_alias: String,
34    default_value: Vec<u8>,
35    has_default_value: bool,
36}
37
38impl std::fmt::Display for DCParameter<'_> {
39    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40        writeln!(f, "TODO")
41    }
42}
43
44impl LegacyDCHash for DCParameter<'_> {
45    fn generate_hash(&self, hashgen: &mut DCHashGenerator) {
46        self.base_type.generate_hash(hashgen);
47    }
48}
49
50impl<'dc> DCParameter<'dc> {
51    #[inline(always)]
52    pub fn get_atomic_field(&self) -> &'dc DCAtomicField {
53        self.parent
54    }
55
56    #[inline(always)]
57    pub fn has_default_value(&self) -> bool {
58        self.has_default_value
59    }
60
61    #[inline(always)]
62    pub fn get_default_value(&self) -> Vec<u8> {
63        self.default_value.clone()
64    }
65
66    pub fn set_type(&mut self, dtype: DCTypeDefinition) {
67        self.base_type = dtype;
68    }
69
70    pub fn set_identifier(&mut self, name: &str) {
71        self.identifier = Some(name.to_owned());
72    }
73
74    pub fn set_default_value(&mut self, v: Vec<u8>) {
75        self.default_value = v;
76        self.has_default_value = true;
77    }
78}