#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "cli", derive(clap::ValueEnum))]
pub enum Version {
V0,
V1,
V2,
#[default]
V3,
}
static VERSION: std::sync::OnceLock<Version> = std::sync::OnceLock::<Version>::new();
pub fn version() -> Version {
*VERSION.get_or_init(|| Version::V3)
}
pub fn init_version(v: Version) {
if let Err(existing) = VERSION.set(v) {
assert_eq!(existing, v, "version already set to {existing:?}, cannot change to {v:?}");
}
}
impl Version {
pub fn suffix(self) -> &'static str {
match self {
Self::V0 => "",
Self::V1 => "_v1",
Self::V2 => "_v2",
Self::V3 => "_v3",
}
}
pub fn clustering_suffix(self) -> &'static str {
match self {
Self::V0 => "",
Self::V1 | Self::V2 | Self::V3 => "_v1",
}
}
}
impl std::fmt::Display for Version {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::V0 => write!(f, "v0"),
Self::V1 => write!(f, "v1"),
Self::V2 => write!(f, "v2"),
Self::V3 => write!(f, "v3"),
}
}
}