37 lines
832 B
Rust
37 lines
832 B
Rust
#![deny(missing_docs)]
|
|
//! An implementation of a key/value store
|
|
use std::collections::HashMap;
|
|
|
|
#[derive(Debug, Default)]
|
|
/// A key/value store
|
|
pub struct KvStore {
|
|
store: HashMap<String, String>,
|
|
}
|
|
|
|
impl KvStore {
|
|
/// Create a new store
|
|
pub fn new() -> Self {
|
|
KvStore {
|
|
store: HashMap::new(),
|
|
}
|
|
}
|
|
|
|
/// Set a key/value pair
|
|
pub fn set(&mut self, key: String, value: String) {
|
|
self.store.insert(key, value);
|
|
}
|
|
|
|
/// Get the value at the specified key
|
|
pub fn get(&mut self, key: String) -> Option<String> {
|
|
match self.store.get(&key) {
|
|
Some(s) => Some(s.to_owned()),
|
|
None => None,
|
|
}
|
|
}
|
|
|
|
/// Remove the value at the specified key
|
|
pub fn remove(&mut self, key: String) {
|
|
self.store.remove(&key);
|
|
}
|
|
}
|