appcore_contracts/policy/module.rs
1// =============================================================================
2// #######
3// ### ### F: module.rs
4// ## ## ## ## P: AppCore-Runtime
5// ## ##
6// C: 2026/07/22 15:41:18 by dnettoRaw
7// ## ## ## ## U: 2026/07/22 15:41:18 by dnettoRaw
8// ########### S: 1.0.1-rc.8
9// =============================================================================
10
11use super::*;
12
13/// Application module declaration.
14#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
15pub struct ModuleDeclaration {
16 id: ModuleId,
17 version: String,
18 required: bool,
19}
20
21impl ModuleDeclaration {
22 /// Creates an application module declaration.
23 pub fn new(id: ModuleId, version: impl Into<String>, required: bool) -> ContractResult<Self> {
24 let module = Self {
25 id,
26 version: version.into(),
27 required,
28 };
29 module.validate()?;
30 Ok(module)
31 }
32
33 /// Returns the module identity.
34 pub fn id(&self) -> &ModuleId {
35 &self.id
36 }
37
38 /// Returns the module version.
39 pub fn version(&self) -> &str {
40 &self.version
41 }
42
43 /// Reports whether the module is required.
44 pub fn is_required(&self) -> bool {
45 self.required
46 }
47
48 pub(crate) fn validate(&self) -> ContractResult<()> {
49 validate_text("module.version", &self.version, 64)
50 }
51}