diff --git a/src/config/client.rs b/src/config/client.rs index 23f98f7..ad8426d 100644 --- a/src/config/client.rs +++ b/src/config/client.rs @@ -11,6 +11,7 @@ use validator::{Validate, ValidationError}; #[derive(Deserialize, Serialize, Validate, Debug)] pub struct Config { + #[validate(custom(function = "super::ensure_latest_revision"))] pub config_revision: Revision, #[validate(nested)] pub theme: Option, diff --git a/src/config/mod.rs b/src/config/mod.rs index 065dd60..c9a4a73 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -4,6 +4,7 @@ pub mod server; use clap::ValueEnum; use enum_iterator::Sequence; use serde_repr::{Deserialize_repr, Serialize_repr}; +use validator::ValidationError; pub const SERVER_CONFIG_PATH: &str = "config/server.toml"; pub const CLIENT_CONFIG_PATH: &str = "config/client.toml"; @@ -19,3 +20,10 @@ pub enum Revision { /// The first revision number for `config/{server,client}.toml` V1, } + +fn ensure_latest_revision(revision: &Revision) -> Result<(), ValidationError> { + match revision.next() { + Some(_) => Err(ValidationError::new("not the latest revision")), + None => Ok(()), + } +} diff --git a/src/config/server.rs b/src/config/server.rs index b4b4d59..b180560 100644 --- a/src/config/server.rs +++ b/src/config/server.rs @@ -11,6 +11,7 @@ use validator::Validate; #[derive(Deserialize, Serialize, Validate, Debug)] pub struct Config { + #[validate(custom(function = "super::ensure_latest_revision"))] pub config_revision: Revision, #[validate(nested)] pub info: Option,