Make config use dropdown

This commit is contained in:
Michael Mikovsky
2025-12-02 08:22:03 -07:00
parent 7f2b145a7a
commit 7fb9aaf534
5 changed files with 205 additions and 80 deletions
+25 -11
View File
@@ -1,3 +1,5 @@
use std::collections::HashMap;
use sled::Tree;
use unshell_lib::error;
@@ -28,17 +30,6 @@ impl Database {
.collect::<Vec<String>>()
}
pub fn get_keys(&self, tree_name: &str) -> Result<Vec<String>, String> {
Ok(self
.get_tree(tree_name)?
.iter()
.keys()
.map(|key| {
String::from_utf8_lossy(&key.expect("This key should exist").to_vec()).to_string()
})
.collect::<Vec<String>>())
}
pub fn put_value(&self, tree_name: &str, key: &str, value: &str) -> Result<(), String> {
match self.get_tree(tree_name)?.insert(key, value) {
Ok(_) => Ok(()),
@@ -62,6 +53,29 @@ impl Database {
}
}
}
pub fn get_keys(&self, tree_name: &str) -> Result<Vec<String>, String> {
Ok(self
.get_tree(tree_name)?
.iter()
.keys()
.map(|key| {
String::from_utf8_lossy(&key.expect("This key should exist").to_vec()).to_string()
})
.collect::<Vec<String>>())
}
pub fn all_tree_values(&self, tree_name: &str) -> Result<HashMap<String, String>, String> {
Ok(self
.get_keys(tree_name)?
.iter()
.map(|key| -> Result<(String, String), String> {
Ok((key.clone(), self.get_value(tree_name, &key)?))
})
.collect::<Result<Vec<(String, String)>, String>>()?
.into_iter()
.collect::<HashMap<String, String>>())
}
}
impl Drop for Database {