ensure that revision is latest in validation
This commit is contained in:
parent
e59f549eeb
commit
ec627458d2
3 changed files with 10 additions and 0 deletions
|
@ -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>,
|
||||
|
|
|
@ -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(()),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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>,
|
||||
|
|
Loading…
Reference in a new issue