use std::path::PathBuf;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum AppendFsync {
Always,
EverySec,
No,
}
impl AppendFsync {
pub fn as_str(&self) -> &'static str {
match self {
Self::Always => "always",
Self::EverySec => "everysec",
Self::No => "no",
}
}
pub fn parse(s: &str) -> Option<Self> {
match s.to_ascii_lowercase().as_str() {
"always" => Some(Self::Always),
"everysec" => Some(Self::EverySec),
"no" => Some(Self::No),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum EvictionPolicy {
NoEviction,
AllKeysLru,
AllKeysLfu,
AllKeysRandom,
VolatileLru,
VolatileLfu,
VolatileRandom,
VolatileTtl,
}
impl EvictionPolicy {
pub fn as_str(&self) -> &'static str {
match self {
Self::NoEviction => "noeviction",
Self::AllKeysLru => "allkeys-lru",
Self::AllKeysLfu => "allkeys-lfu",
Self::AllKeysRandom => "allkeys-random",
Self::VolatileLru => "volatile-lru",
Self::VolatileLfu => "volatile-lfu",
Self::VolatileRandom => "volatile-random",
Self::VolatileTtl => "volatile-ttl",
}
}
pub fn parse(s: &str) -> Option<Self> {
match s.to_ascii_lowercase().as_str() {
"noeviction" => Some(Self::NoEviction),
"allkeys-lru" => Some(Self::AllKeysLru),
"allkeys-lfu" => Some(Self::AllKeysLfu),
"allkeys-random" => Some(Self::AllKeysRandom),
"volatile-lru" => Some(Self::VolatileLru),
"volatile-lfu" => Some(Self::VolatileLfu),
"volatile-random" => Some(Self::VolatileRandom),
"volatile-ttl" => Some(Self::VolatileTtl),
_ => None,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum LogLevel {
Trace,
Debug,
Info,
Warn,
Error,
}
impl LogLevel {
pub fn as_str(&self) -> &'static str {
match self {
Self::Trace => "trace",
Self::Debug => "debug",
Self::Info => "info",
Self::Warn => "warning",
Self::Error => "error",
}
}
pub fn parse(s: &str) -> Option<Self> {
match s.to_ascii_lowercase().as_str() {
"trace" => Some(Self::Trace),
"debug" => Some(Self::Debug),
"info" => Some(Self::Info),
"warn" | "warning" => Some(Self::Warn),
"error" => Some(Self::Error),
_ => None,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum LogOutput {
Stderr,
Stdout,
File(PathBuf),
}
impl LogOutput {
pub fn as_str(&self) -> std::borrow::Cow<'_, str> {
match self {
Self::Stderr => "stderr".into(),
Self::Stdout => "stdout".into(),
Self::File(p) => p.display().to_string().into(),
}
}
pub fn parse(s: &str) -> Self {
match s {
"stderr" => Self::Stderr,
"stdout" => Self::Stdout,
path => Self::File(PathBuf::from(path)),
}
}
}