mirror of
https://github.com/Astatin3/unshell.git
synced 2026-06-09 06:47:59 -06:00
Make config use dropdown
This commit is contained in:
Generated
+67
-13
@@ -485,6 +485,15 @@ version = "0.1.2"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
|
checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "ecolor"
|
||||||
|
version = "0.31.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "bc4feb366740ded31a004a0e4452fbf84e80ef432ecf8314c485210229672fd1"
|
||||||
|
dependencies = [
|
||||||
|
"emath 0.31.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ecolor"
|
name = "ecolor"
|
||||||
version = "0.33.2"
|
version = "0.33.2"
|
||||||
@@ -492,7 +501,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "084980ebede2fb1ad6c4f54285b3e489052ef2b6aa4016e4c19349417adc75c5"
|
checksum = "084980ebede2fb1ad6c4f54285b3e489052ef2b6aa4016e4c19349417adc75c5"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"emath",
|
"emath 0.33.2",
|
||||||
"serde",
|
"serde",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -505,7 +514,7 @@ dependencies = [
|
|||||||
"ahash",
|
"ahash",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"document-features",
|
"document-features",
|
||||||
"egui",
|
"egui 0.33.2",
|
||||||
"egui-wgpu",
|
"egui-wgpu",
|
||||||
"egui-winit",
|
"egui-winit",
|
||||||
"egui_glow",
|
"egui_glow",
|
||||||
@@ -534,6 +543,20 @@ dependencies = [
|
|||||||
"winit",
|
"winit",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "egui"
|
||||||
|
version = "0.31.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "25dd34cec49ab55d85ebf70139cb1ccd29c977ef6b6ba4fe85489d6877ee9ef3"
|
||||||
|
dependencies = [
|
||||||
|
"ahash",
|
||||||
|
"bitflags 2.10.0",
|
||||||
|
"emath 0.31.1",
|
||||||
|
"epaint 0.31.1",
|
||||||
|
"nohash-hasher",
|
||||||
|
"profiling",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui"
|
name = "egui"
|
||||||
version = "0.33.2"
|
version = "0.33.2"
|
||||||
@@ -543,8 +566,8 @@ dependencies = [
|
|||||||
"accesskit",
|
"accesskit",
|
||||||
"ahash",
|
"ahash",
|
||||||
"bitflags 2.10.0",
|
"bitflags 2.10.0",
|
||||||
"emath",
|
"emath 0.33.2",
|
||||||
"epaint",
|
"epaint 0.33.2",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
"profiling",
|
"profiling",
|
||||||
@@ -554,6 +577,15 @@ dependencies = [
|
|||||||
"unicode-segmentation",
|
"unicode-segmentation",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "egui-dropdown"
|
||||||
|
version = "0.13.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "82d277c6c1f49e4e227344e920132d2d22a51810296b5c78f90e6aef4eed63ea"
|
||||||
|
dependencies = [
|
||||||
|
"egui 0.31.1",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "egui-wgpu"
|
name = "egui-wgpu"
|
||||||
version = "0.33.2"
|
version = "0.33.2"
|
||||||
@@ -563,8 +595,8 @@ dependencies = [
|
|||||||
"ahash",
|
"ahash",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"document-features",
|
"document-features",
|
||||||
"egui",
|
"egui 0.33.2",
|
||||||
"epaint",
|
"epaint 0.33.2",
|
||||||
"log",
|
"log",
|
||||||
"profiling",
|
"profiling",
|
||||||
"thiserror 2.0.17",
|
"thiserror 2.0.17",
|
||||||
@@ -582,7 +614,7 @@ checksum = "4772ed5f16fa8ec2ba295e58f62b58ee83fcf49e67ec13d2b7ddf4e9a2dea34e"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"arboard",
|
"arboard",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui 0.33.2",
|
||||||
"log",
|
"log",
|
||||||
"objc2 0.5.2",
|
"objc2 0.5.2",
|
||||||
"objc2-foundation 0.2.2",
|
"objc2-foundation 0.2.2",
|
||||||
@@ -603,7 +635,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "550e844e608e356f4ad6843c510aa9bb5838b427e4700ed0056e9746ceeed866"
|
checksum = "550e844e608e356f4ad6843c510aa9bb5838b427e4700ed0056e9746ceeed866"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"egui",
|
"egui 0.33.2",
|
||||||
"enum-map",
|
"enum-map",
|
||||||
"log",
|
"log",
|
||||||
"mime_guess2",
|
"mime_guess2",
|
||||||
@@ -617,7 +649,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "17b94ff67a1d18933fff2519f5f57c388f932c093036c381fb9ae2853b3e1e09"
|
checksum = "17b94ff67a1d18933fff2519f5f57c388f932c093036c381fb9ae2853b3e1e09"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"egui",
|
"egui 0.33.2",
|
||||||
"glow",
|
"glow",
|
||||||
"log",
|
"log",
|
||||||
"memoffset",
|
"memoffset",
|
||||||
@@ -634,7 +666,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "ebfac3ca35f5e4fe217d3b03312111b234fe55ce059faf62b4cb47f7cf6d54f1"
|
checksum = "ebfac3ca35f5e4fe217d3b03312111b234fe55ce059faf62b4cb47f7cf6d54f1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ahash",
|
"ahash",
|
||||||
"egui",
|
"egui 0.33.2",
|
||||||
"itertools",
|
"itertools",
|
||||||
"log",
|
"log",
|
||||||
"serde",
|
"serde",
|
||||||
@@ -646,6 +678,12 @@ version = "1.15.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "emath"
|
||||||
|
version = "0.31.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "9e4cadcff7a5353ba72b7fea76bf2122b5ebdbc68e8155aa56dfdea90083fe1b"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "emath"
|
name = "emath"
|
||||||
version = "0.33.2"
|
version = "0.33.2"
|
||||||
@@ -687,6 +725,21 @@ dependencies = [
|
|||||||
"syn",
|
"syn",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "epaint"
|
||||||
|
version = "0.31.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "41fcc0f5a7c613afd2dee5e4b30c3e6acafb8ad6f0edb06068811f708a67c562"
|
||||||
|
dependencies = [
|
||||||
|
"ab_glyph",
|
||||||
|
"ahash",
|
||||||
|
"ecolor 0.31.1",
|
||||||
|
"emath 0.31.1",
|
||||||
|
"nohash-hasher",
|
||||||
|
"parking_lot",
|
||||||
|
"profiling",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "epaint"
|
name = "epaint"
|
||||||
version = "0.33.2"
|
version = "0.33.2"
|
||||||
@@ -696,8 +749,8 @@ dependencies = [
|
|||||||
"ab_glyph",
|
"ab_glyph",
|
||||||
"ahash",
|
"ahash",
|
||||||
"bytemuck",
|
"bytemuck",
|
||||||
"ecolor",
|
"ecolor 0.33.2",
|
||||||
"emath",
|
"emath 0.33.2",
|
||||||
"epaint_default_fonts",
|
"epaint_default_fonts",
|
||||||
"log",
|
"log",
|
||||||
"nohash-hasher",
|
"nohash-hasher",
|
||||||
@@ -2401,7 +2454,8 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
"eframe",
|
"eframe",
|
||||||
"egui",
|
"egui 0.33.2",
|
||||||
|
"egui-dropdown",
|
||||||
"egui_extras",
|
"egui_extras",
|
||||||
"egui_tiles",
|
"egui_tiles",
|
||||||
"log",
|
"log",
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ wasm-bindgen = "0.2.106"
|
|||||||
web-sys = "0.3.70" # to access the DOM (to hide the loading text)
|
web-sys = "0.3.70" # to access the DOM (to hide the loading text)
|
||||||
serde_json = "1.0.145"
|
serde_json = "1.0.145"
|
||||||
chrono = "0.4.42"
|
chrono = "0.4.42"
|
||||||
|
egui-dropdown = "0.13.0"
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
opt-level = 2 # fast and small wasm
|
opt-level = 2 # fast and small wasm
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
use std::sync::{
|
use std::{
|
||||||
Arc, Mutex,
|
collections::HashMap,
|
||||||
atomic::{AtomicBool, Ordering},
|
sync::{Arc, Mutex},
|
||||||
};
|
};
|
||||||
|
|
||||||
use egui::Color32;
|
use egui::ComboBox;
|
||||||
|
use egui_extras::{Column, TableBuilder};
|
||||||
|
|
||||||
use crate::auth::Auth;
|
use crate::auth::Auth;
|
||||||
|
|
||||||
@@ -20,7 +21,7 @@ pub struct Config {
|
|||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct ConfigState {
|
struct ConfigState {
|
||||||
trees: Option<Vec<String>>,
|
trees: Option<Vec<String>>,
|
||||||
tree_keys: Option<Vec<String>>,
|
tree_keys: Option<HashMap<String, String>>,
|
||||||
is_requesting: bool,
|
is_requesting: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,9 +41,9 @@ impl Default for Config {
|
|||||||
|
|
||||||
impl Config {
|
impl Config {
|
||||||
pub fn update(&mut self, auth: &mut Auth, ui: &mut egui::Ui) {
|
pub fn update(&mut self, auth: &mut Auth, ui: &mut egui::Ui) {
|
||||||
let mut state_lock = self.state.lock().unwrap();
|
let state_lock = self.state.lock().unwrap();
|
||||||
let tree_list_none = state_lock.trees.is_none();
|
let mut tree_list_none = state_lock.trees.is_none();
|
||||||
let key_list_none = state_lock.tree_keys.is_none();
|
let mut key_list_none = state_lock.tree_keys.is_none();
|
||||||
let is_requesting = state_lock.is_requesting;
|
let is_requesting = state_lock.is_requesting;
|
||||||
|
|
||||||
if !tree_list_none
|
if !tree_list_none
|
||||||
@@ -57,12 +58,18 @@ impl Config {
|
|||||||
|
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
if ui.button("Refresh").clicked() {
|
|
||||||
self.tree_option.clear();
|
|
||||||
(*self.state.lock().unwrap()).trees = None;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
if ui.button("Refresh").clicked() {
|
||||||
|
// self.tree_option.clear();
|
||||||
|
let mut state_lock = self.state.lock().unwrap();
|
||||||
|
(*state_lock).trees = None;
|
||||||
|
(*state_lock).tree_keys = None;
|
||||||
|
drop(state_lock);
|
||||||
|
|
||||||
|
tree_list_none = true;
|
||||||
|
key_list_none = true;
|
||||||
|
}
|
||||||
|
|
||||||
if tree_list_none && !is_requesting {
|
if tree_list_none && !is_requesting {
|
||||||
self.state.lock().unwrap().is_requesting = true;
|
self.state.lock().unwrap().is_requesting = true;
|
||||||
let state_clone = self.state.clone();
|
let state_clone = self.state.clone();
|
||||||
@@ -76,57 +83,42 @@ impl Config {
|
|||||||
} else if tree_list_none && is_requesting {
|
} else if tree_list_none && is_requesting {
|
||||||
ui.spinner();
|
ui.spinner();
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
let state_lock = self.state.lock().unwrap();
|
||||||
|
// This might have changed since the above api call
|
||||||
|
tree_list_none = state_lock.trees.is_none();
|
||||||
|
|
||||||
if !tree_list_none {
|
if !tree_list_none {
|
||||||
// let tree_len = self.state.lock().unwrap().trees.as_ref().unwrap().len();
|
|
||||||
|
|
||||||
// for tree in &state_lock.unwrap() {
|
|
||||||
// if ui.button(tree).clicked() {
|
|
||||||
// self.tree_option = tree.to_string();
|
|
||||||
// (*state_lock).tree_keys.as_mut();
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
let state_lock = self.state.lock().unwrap();
|
|
||||||
let trees = state_lock.trees.as_ref().unwrap().clone();
|
let trees = state_lock.trees.as_ref().unwrap().clone();
|
||||||
drop(state_lock);
|
drop(state_lock);
|
||||||
|
|
||||||
for tree in trees {
|
let before = &self.tree_option.clone();
|
||||||
// let tree: &&String = self
|
egui::ComboBox::from_id_salt("Select Tree")
|
||||||
// .state
|
.selected_text(&self.tree_option)
|
||||||
// .lock()
|
.show_ui(ui, |ui| {
|
||||||
// .unwrap()
|
for tree in trees {
|
||||||
// .tree_keys
|
ui.selectable_value(&mut self.tree_option, tree.clone(), tree);
|
||||||
// .unwrap()
|
}
|
||||||
// .iter()
|
});
|
||||||
// .nth(i)
|
|
||||||
// .unwrap();
|
|
||||||
|
|
||||||
// let tree sel
|
if before.ne(&self.tree_option) {
|
||||||
|
(*self.state.lock().unwrap()).tree_keys = None;
|
||||||
if ui.button(&tree).clicked() {
|
key_list_none = true;
|
||||||
self.tree_option = tree.to_string();
|
|
||||||
(*self.state.lock().unwrap()).tree_keys = None;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
|
||||||
if !self.tree_option.is_empty() && !tree_list_none {
|
if !self.tree_option.is_empty() && !tree_list_none {
|
||||||
ui.horizontal(|ui| {
|
// ui.horizontal(|ui| {
|
||||||
ui.label(&format!("Tree: {}", self.tree_option));
|
// ui.label(&format!("Tree: {}", self.tree_option));
|
||||||
});
|
// });
|
||||||
|
|
||||||
ui.horizontal(|ui| {
|
|
||||||
if key_list_none && !is_requesting {
|
if key_list_none && !is_requesting {
|
||||||
self.state.lock().unwrap().is_requesting = true;
|
self.state.lock().unwrap().is_requesting = true;
|
||||||
let state_clone = self.state.clone();
|
let state_clone = self.state.clone();
|
||||||
|
|
||||||
auth.get(
|
auth.get(
|
||||||
&format!("/api/keys/{}", self.tree_option),
|
&format!("/api/values/{}", self.tree_option),
|
||||||
move |response: Result<Vec<String>, String>| {
|
move |response: Result<HashMap<String, String>, String>| {
|
||||||
let mut state_lock = state_clone.lock().unwrap();
|
let mut state_lock = state_clone.lock().unwrap();
|
||||||
state_lock.tree_keys = Some(response.unwrap());
|
state_lock.tree_keys = Some(response.unwrap());
|
||||||
state_lock.is_requesting = false;
|
state_lock.is_requesting = false;
|
||||||
@@ -134,13 +126,58 @@ impl Config {
|
|||||||
);
|
);
|
||||||
} else if key_list_none && is_requesting {
|
} else if key_list_none && is_requesting {
|
||||||
ui.spinner();
|
ui.spinner();
|
||||||
} else {
|
|
||||||
ui.label(&format!(
|
|
||||||
"Keys: {:?}",
|
|
||||||
self.state.lock().unwrap().tree_keys.clone()
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if !key_list_none {
|
||||||
|
// let body_text_size = TextStyle::Body.resolve(ui.style()).size;
|
||||||
|
// use egui_extras::{Size, StripBuilder};
|
||||||
|
// StripBuilder::new(ui)
|
||||||
|
// .size(Size::remainder().at_least(100.0)) // for the table
|
||||||
|
// .size(Size::exact(body_text_size))
|
||||||
|
// .vertical(|mut strip| {
|
||||||
|
// strip.cell(|ui| {
|
||||||
|
|
||||||
|
egui::ScrollArea::both().show(ui, |ui| {
|
||||||
|
let table = TableBuilder::new(ui)
|
||||||
|
.striped(true)
|
||||||
|
.resizable(true)
|
||||||
|
.cell_layout(egui::Layout::left_to_right(egui::Align::Center))
|
||||||
|
.column(Column::auto())
|
||||||
|
.column(Column::auto())
|
||||||
|
.min_scrolled_height(0.0)
|
||||||
|
.sense(egui::Sense::click());
|
||||||
|
|
||||||
|
table
|
||||||
|
.header(20., |mut header| {
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.strong("key");
|
||||||
|
});
|
||||||
|
header.col(|ui| {
|
||||||
|
ui.strong("value");
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.body(|mut body| {
|
||||||
|
let state_lock = self.state.lock().unwrap();
|
||||||
|
let map = state_lock.tree_keys.as_ref().unwrap();
|
||||||
|
|
||||||
|
for (key, value) in (map).iter() {
|
||||||
|
// // let runtime = self.current_runtimes
|
||||||
|
|
||||||
|
body.row(18., |mut row| {
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(key);
|
||||||
|
});
|
||||||
|
row.col(|ui| {
|
||||||
|
ui.label(value);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
// });
|
||||||
|
// });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ pub async fn start_api(address: &str, database: Database) {
|
|||||||
|
|
||||||
let mut router = Router::new().route("/api/auth", post(auth::sign_in));
|
let mut router = Router::new().route("/api/auth", post(auth::sign_in));
|
||||||
router = route_get_trees(router);
|
router = route_get_trees(router);
|
||||||
router = route_get_keys(router);
|
router = route_get_all_tree_values(router);
|
||||||
|
router = route_get_tree_keys(router);
|
||||||
router = route_trees(router);
|
router = route_trees(router);
|
||||||
|
|
||||||
axum::serve(listener, router.with_state(database))
|
axum::serve(listener, router.with_state(database))
|
||||||
@@ -46,7 +47,7 @@ fn route_get_trees(router: Router<Database>) -> Router<Database> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Route the "keys" api for each tree
|
// Route the "keys" api for each tree
|
||||||
fn route_get_keys(router: Router<Database>) -> Router<Database> {
|
fn route_get_tree_keys(router: Router<Database>) -> Router<Database> {
|
||||||
router.route(
|
router.route(
|
||||||
"/api/keys/{*path}",
|
"/api/keys/{*path}",
|
||||||
get(
|
get(
|
||||||
@@ -63,6 +64,24 @@ fn route_get_keys(router: Router<Database>) -> Router<Database> {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Route the "values" api to get all the values for each tree
|
||||||
|
fn route_get_all_tree_values(router: Router<Database>) -> Router<Database> {
|
||||||
|
router.route(
|
||||||
|
"/api/values/{*path}",
|
||||||
|
get(
|
||||||
|
async |State(database): State<Database>,
|
||||||
|
Path(path): Path<String>,
|
||||||
|
Extension(_): Extension<CurrentUser>| {
|
||||||
|
debug!("GET /api/values/{}", path);
|
||||||
|
let result = database.all_tree_values(&path);
|
||||||
|
|
||||||
|
Json(serde_json::to_value(result).unwrap())
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.layer(middleware::from_fn(auth::authorize)),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// Loop through all trees and add /api/<tree>/<path> POST aand GET listeners for them
|
// Loop through all trees and add /api/<tree>/<path> POST aand GET listeners for them
|
||||||
fn route_trees(mut router: Router<Database>) -> Router<Database> {
|
fn route_trees(mut router: Router<Database>) -> Router<Database> {
|
||||||
for tree in crate::DATABASE_TREES.iter() {
|
for tree in crate::DATABASE_TREES.iter() {
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use sled::Tree;
|
use sled::Tree;
|
||||||
use unshell_lib::error;
|
use unshell_lib::error;
|
||||||
|
|
||||||
@@ -28,17 +30,6 @@ impl Database {
|
|||||||
.collect::<Vec<String>>()
|
.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> {
|
pub fn put_value(&self, tree_name: &str, key: &str, value: &str) -> Result<(), String> {
|
||||||
match self.get_tree(tree_name)?.insert(key, value) {
|
match self.get_tree(tree_name)?.insert(key, value) {
|
||||||
Ok(_) => Ok(()),
|
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 {
|
impl Drop for Database {
|
||||||
|
|||||||
Reference in New Issue
Block a user