use async_trait::async_trait;
use std::collections::HashMap;
pub mod memory;
pub enum ThawAction {
Thaw,
Discard,
Keep,
}
#[async_trait]
pub trait SessionManager: Send + Sync {
async fn set(&self, username: &str, vars: HashMap<String, String>);
async fn add_history(&self, username: &str, input: &str, reply: &str);
async fn get_history(&self, username: &str) -> History;
async fn get(&self, username: &str, name: &str) -> String;
async fn get_any(&self, username: &str) -> HashMap<String, String>;
async fn get_all(&self) -> HashMap<String, HashMap<String, String>>;
async fn clear(&self, username: &str);
async fn clear_all(&self);
async fn freeze(&self, username: &str) -> Result<bool, String>;
async fn thaw(&self, username: &str, action: ThawAction) -> Result<bool, String>;
}
#[derive(Debug, Clone)]
pub struct History {
pub input: Vec<String>,
pub reply: Vec<String>,
}
impl Default for History {
fn default() -> Self {
Self {
input: vec!["undefined".to_string(); crate::MAX_HISTORY],
reply: vec!["undefined".to_string(); crate::MAX_HISTORY],
}
}
}