Skip to main content

rvaultlib/types/
mod.rs

1#[derive(Debug, Clone, Copy, PartialEq, Eq)]
2pub enum ValueType {
3    Object,
4    Array,
5    String,
6    Bool,
7    Number,
8    Integer,
9    Null,
10}
11
12impl std::fmt::Display for ValueType {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            ValueType::Object => write!(f, "Object"),
16            ValueType::Array => write!(f, "Array"),
17            ValueType::String => write!(f, "String"),
18            ValueType::Bool => write!(f, "Bool"),
19            ValueType::Number => write!(f, "Number"),
20            ValueType::Integer => write!(f, "Integer"),
21            ValueType::Null => write!(f, "Null"),
22        }
23    }
24}
25
26/// Typed value used during encryption/decryption to preserve the original type.
27#[derive(Debug, Clone, PartialEq)]
28pub enum TypedValue {
29    String(String),
30    Integer(i64),
31    Bool(bool),
32    Number(f64),
33    Null,
34}
35
36/// Controls whether a value should be processed, skipped, or processing cancelled.
37#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum ProcessHandling {
39    Process,
40    Skip,
41    Cancel,
42}
43
44/// Build a dot-notation key path from a parent path and a key name.
45/// e.g. ("second.a", "v") -> "second.a.v", ("", "first") -> "first"
46pub fn new_key_path(key_path: &str, key: &str) -> String {
47    if key_path.is_empty() {
48        key.to_string()
49    } else {
50        format!("{}.{}", key_path, key)
51    }
52}