use std::collections::HashMap;
pub struct KeyValueStore {
data: HashMap<String, String>,
}
impl KeyValueStore {
pub fn new() -> Self {
KeyValueStore {
data: HashMap::new(),
}
}
pub fn insert(&mut self, key: String, value: String) {
self.data.insert(key, value); }
pub fn get(&self, key: &str) -> Option<&String> {
self.data.get(key)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_insert_and_get() {
let mut store = KeyValueStore::new();
store.insert("hello".to_string(), "world".to_string());
assert_eq!(store.get("hello"), Some(&"world".to_string()));
}
}