starweaver_context/
state.rs1use std::collections::BTreeMap;
4
5use serde::{Deserialize, Serialize};
6use serde_json::Value;
7
8#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
10pub struct StateStore {
11 domains: BTreeMap<String, Value>,
12}
13
14impl StateStore {
15 #[must_use]
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn set(&mut self, key: impl Into<String>, value: Value) {
23 self.domains.insert(key.into(), value);
24 }
25
26 #[must_use]
28 pub fn get(&self, key: &str) -> Option<&Value> {
29 self.domains.get(key)
30 }
31
32 pub fn remove(&mut self, key: &str) -> Option<Value> {
34 self.domains.remove(key)
35 }
36
37 #[must_use]
39 pub fn is_empty(&self) -> bool {
40 self.domains.is_empty()
41 }
42
43 #[must_use]
45 #[allow(clippy::missing_const_for_fn)]
46 pub fn domains(&self) -> &BTreeMap<String, Value> {
47 &self.domains
48 }
49}