use std::path::PathBuf;
use serde::{Deserialize, Serialize};
use crate::snapshot::error::SnapshotError;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SnapshotFormat {
Bincode,
Json,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Compression {
None,
#[cfg(feature = "snapshot-zstd")]
Zstd {
level: i32,
},
#[cfg_attr(docsrs, doc(cfg(feature = "snapshot-lz4")))]
#[cfg(feature = "snapshot-lz4")]
Lz4,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SnapshotConfig {
pub dir: PathBuf,
pub name: String,
#[serde(skip)]
pub key: Option<String>,
pub format: SnapshotFormat,
pub compression: Compression,
pub keep: usize,
}
pub fn sanitize_key(key: &str) -> Result<String, SnapshotError> {
let s: String = key
.chars()
.map(|c| {
if c.is_ascii_alphanumeric() || c == '_' || c == '.' || c == '-' {
c
} else {
'_'
}
})
.collect();
if s.trim_matches('_').is_empty() {
Err(SnapshotError::InvalidKey(key.to_string()))
} else {
Ok(s)
}
}