Skip to main content

speck_core/format/
manifest.rs

1//! Module manifest for metadata and dependencies
2
3use alloc::string::String;
4use alloc::vec::Vec;
5use serde::{Serialize, Deserialize};
6
7/// Module metadata manifest
8#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
9pub struct ModuleManifest {
10    /// Human-readable name
11    pub name: String,
12    
13    /// Semantic version string
14    pub version: String,
15    
16    /// Author or vendor
17    pub author: Option<String>,
18    
19    /// Description
20    pub description: Option<String>,
21    
22    /// Build timestamp (ISO 8601)
23    pub built_at: Option<String>,
24    
25    /// Required dependencies (module name -> min version)
26    pub dependencies: Vec<Dependency>,
27    
28    /// Maximum stack usage (bytes)
29    pub stack_size: Option<u32>,
30    
31    /// Static RAM requirement (bytes)
32    pub ram_size: Option<u32>,
33}
34
35/// Dependency specification
36#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
37pub struct Dependency {
38    /// Module name
39    pub name: String,
40    /// Minimum required version
41    pub min_version: String,
42    /// Maximum compatible version (exclusive)
43    pub max_version: Option<String>,
44}
45
46impl ModuleManifest {
47    /// Serialize to TOML bytes
48    #[cfg(feature = "std")]
49    pub fn to_toml(&self) -> Result<String, toml::ser::Error> {
50        toml::to_string_pretty(self)
51    }
52    
53    /// Deserialize from TOML
54    #[cfg(feature = "std")]
55    pub fn from_toml(s: &str) -> Result<Self, toml::de::Error> {
56        toml::from_str(s)
57    }
58    
59    /// Serialize to JSON bytes
60    pub fn to_json(&self) -> Result<String, serde_json::Error> {
61        serde_json::to_string_pretty(self)
62    }
63    
64    /// Deserialize from JSON
65    pub fn from_json(s: &str) -> Result<Self, serde_json::Error> {
66        serde_json::from_str(s)
67    }
68}