/// Provides utilites for storing and retrieving various named string tokens which are needed. use crate::error::unexpected; use std::{collections, sync}; pub trait Store { fn get(&self, key: &str) -> unexpected::Result>; fn set(&self, key: String, val: String) -> unexpected::Result<()>; fn del(&self, key: &str) -> unexpected::Result<()>; } pub struct MemStore { m: sync::Mutex>, } impl MemStore { pub fn new() -> MemStore { MemStore { m: sync::Mutex::default(), } } } impl Store for MemStore { fn get(&self, key: &str) -> unexpected::Result> { Ok(self.m.lock().unwrap().get(key).map(|s| s.to_string())) } fn set(&self, key: String, val: String) -> unexpected::Result<()> { self.m.lock().unwrap().insert(key, val); Ok(()) } fn del(&self, key: &str) -> unexpected::Result<()> { self.m.lock().unwrap().remove(key); Ok(()) } }