38 lines
808 B
Rust
38 lines
808 B
Rust
pub mod user;
|
|
|
|
use std::collections::BTreeMap;
|
|
|
|
#[derive(Debug, Clone)]
|
|
pub struct Context {
|
|
values: BTreeMap<String, String>,
|
|
}
|
|
|
|
impl Context {
|
|
pub fn new() -> Self {
|
|
Self {
|
|
values: Default::default(),
|
|
}
|
|
}
|
|
|
|
pub fn with_value(&self, key: impl Into<String>, value: impl Into<String>) -> Self {
|
|
let mut values = self.values.clone();
|
|
|
|
let _ = values.insert(key.into(), value.into());
|
|
|
|
Self { values }
|
|
}
|
|
|
|
pub fn with_value_mut(
|
|
&mut self,
|
|
key: impl Into<String>,
|
|
value: impl Into<String>,
|
|
) -> &mut Self {
|
|
self.values.insert(key.into(), value.into());
|
|
self
|
|
}
|
|
|
|
pub fn get(&self, key: impl AsRef<str>) -> Option<&str> {
|
|
self.values.get(key.as_ref()).map(|s| s.as_str())
|
|
}
|
|
}
|