kjuulh 6e16fc6b2b
feat: move project to crates
Signed-off-by: kjuulh <contact@kjuulh.io>
2023-10-21 11:14:58 +02:00

24 lines
677 B
Rust

use crate::Context;
pub trait ContextUserExt {
fn set_user_id(&self, user_id: impl Into<String>) -> Context;
fn set_user_id_mut(&mut self, user_id: impl Into<String>) -> &mut Context;
fn get_user_id(&self) -> Option<String>;
}
const USER_ID_KEY: &str = "user_id";
impl ContextUserExt for Context {
fn set_user_id(&self, user_id: impl Into<String>) -> Context {
self.with_value(USER_ID_KEY, user_id)
}
fn set_user_id_mut(&mut self, user_id: impl Into<String>) -> &mut Context {
self.with_value_mut(USER_ID_KEY, user_id)
}
fn get_user_id(&self) -> Option<String> {
self.get(USER_ID_KEY).map(|s| s.to_string())
}
}