use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Default, Deserialize, Eq, PartialEq, Serialize)]
pub struct NoteStore {
notes: BTreeMap<String, String>,
}
impl NoteStore {
#[must_use]
pub fn new() -> Self {
Self::default()
}
pub fn set(&mut self, key: impl Into<String>, value: impl Into<String>) {
self.notes.insert(key.into(), value.into());
}
#[must_use]
pub fn get(&self, key: &str) -> Option<&str> {
self.notes.get(key).map(String::as_str)
}
pub fn delete(&mut self, key: &str) -> bool {
self.notes.remove(key).is_some()
}
#[must_use]
pub fn entries(&self) -> Vec<(String, String)> {
self.notes
.iter()
.map(|(key, value)| (key.clone(), value.clone()))
.collect()
}
#[must_use]
pub fn to_map(&self) -> BTreeMap<String, String> {
self.notes.clone()
}
#[must_use]
pub const fn from_map(notes: BTreeMap<String, String>) -> Self {
Self { notes }
}
#[must_use]
pub fn is_empty(&self) -> bool {
self.notes.is_empty()
}
}