ensure that revision is latest in validation

This commit is contained in:
naskya 2024-06-21 10:36:54 +09:00
parent e59f549eeb
commit ec627458d2
Signed by: naskya
GPG key ID: 712D413B3A9FED5C
3 changed files with 10 additions and 0 deletions

View file

@ -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<Theme>,

View file

@ -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(()),
}
}

View file

@ -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<Info>,