sal_virt/rfs/types.rs
1use std::collections::HashMap;
2
3/// Represents a mounted filesystem
4#[derive(Debug, Clone)]
5pub struct Mount {
6 /// Mount ID
7 pub id: String,
8 /// Source path or URL
9 pub source: String,
10 /// Target mount point
11 pub target: String,
12 /// Filesystem type
13 pub fs_type: String,
14 /// Mount options
15 pub options: Vec<String>,
16}
17
18/// Types of mounts supported by RFS
19#[derive(Debug, Clone)]
20pub enum MountType {
21 /// Local filesystem
22 Local,
23 /// SSH remote filesystem
24 SSH,
25 /// S3 object storage
26 S3,
27 /// WebDAV remote filesystem
28 WebDAV,
29 /// Custom mount type
30 Custom(String),
31}
32
33impl MountType {
34 /// Convert mount type to string representation
35 pub fn to_string(&self) -> String {
36 match self {
37 MountType::Local => "local".to_string(),
38 MountType::SSH => "ssh".to_string(),
39 MountType::S3 => "s3".to_string(),
40 MountType::WebDAV => "webdav".to_string(),
41 MountType::Custom(s) => s.clone(),
42 }
43 }
44
45 /// Create a MountType from a string
46 pub fn from_string(s: &str) -> Self {
47 match s.to_lowercase().as_str() {
48 "local" => MountType::Local,
49 "ssh" => MountType::SSH,
50 "s3" => MountType::S3,
51 "webdav" => MountType::WebDAV,
52 _ => MountType::Custom(s.to_string()),
53 }
54 }
55}
56
57/// Store specification for packing operations
58#[derive(Debug, Clone)]
59pub struct StoreSpec {
60 /// Store type (e.g., "file", "s3")
61 pub spec_type: String,
62 /// Store options
63 pub options: HashMap<String, String>,
64}
65
66impl StoreSpec {
67 /// Create a new store specification
68 ///
69 /// # Arguments
70 ///
71 /// * `spec_type` - Store type (e.g., "file", "s3")
72 ///
73 /// # Returns
74 ///
75 /// * `Self` - New store specification
76 pub fn new(spec_type: &str) -> Self {
77 Self {
78 spec_type: spec_type.to_string(),
79 options: HashMap::new(),
80 }
81 }
82
83 /// Add an option to the store specification
84 ///
85 /// # Arguments
86 ///
87 /// * `key` - Option key
88 /// * `value` - Option value
89 ///
90 /// # Returns
91 ///
92 /// * `Self` - Updated store specification for method chaining
93 pub fn with_option(mut self, key: &str, value: &str) -> Self {
94 self.options.insert(key.to_string(), value.to_string());
95 self
96 }
97
98 /// Convert the store specification to a string
99 ///
100 /// # Returns
101 ///
102 /// * `String` - String representation of the store specification
103 pub fn to_string(&self) -> String {
104 let mut result = self.spec_type.clone();
105
106 if !self.options.is_empty() {
107 result.push_str(":");
108 let options: Vec<String> = self
109 .options
110 .iter()
111 .map(|(k, v)| format!("{}={}", k, v))
112 .collect();
113 result.push_str(&options.join(","));
114 }
115
116 result
117 }
118}