/ src / source / variable.rs
variable.rs
 1  use compact_str::CompactString;
 2  use std::path::PathBuf;
 3  
 4  #[derive(Debug, Clone)]
 5  pub struct ParsedVariable {
 6      pub key: CompactString,
 7      pub raw_value: CompactString,
 8      pub source: VariableSource,
 9      pub description: Option<CompactString>,
10      pub is_commented: bool,
11  }
12  
13  impl ParsedVariable {
14      pub fn simple(
15          key: impl Into<CompactString>,
16          value: impl Into<CompactString>,
17          source: VariableSource,
18      ) -> Self {
19          Self {
20              key: key.into(),
21              raw_value: value.into(),
22              source,
23              description: None,
24              is_commented: false,
25          }
26      }
27  }
28  
29  #[derive(Debug, Clone, PartialEq, Eq)]
30  pub enum VariableSource {
31      File {
32          path: PathBuf,
33          offset: usize,
34      },
35      Shell,
36      Memory,
37      Remote {
38          provider: CompactString,
39          path: Option<String>,
40      },
41  }
42  
43  impl VariableSource {
44      pub fn file_path(&self) -> Option<&PathBuf> {
45          match self {
46              VariableSource::File { path, .. } => Some(path),
47              _ => None,
48          }
49      }
50  }