Trait ValidatePort

Source
pub trait ValidatePort: Send + Sync {
    // Required methods
    fn validate(
        &self,
        raw: RawConfig,
    ) -> Result<ValidatedConfig, Vec<ConfigError>>;
    fn validate_color(&self, value: &str, key: &str) -> Result<()>;
    fn validate_spacing(&self, value: u16, key: &str) -> Result<()>;
}
Expand description

Port for validating configuration data.

ValidatePort handles the validation of raw configuration data, checking that all values are correct and producing helpful error messages when they are not.

§Validation Rules

The validator checks:

CategoryValidation
ColorsValid hex format, correct length
NumbersWithin valid ranges
StringsNon-empty where required
StructureRequired fields present
KeysWarning for unknown keys

§Example

ⓘ
use fernctl::ports::inbound::ValidatePort;

let validator = DefaultValidator::new();
let result = validator.validate(&raw_config);

match result {
    Ok(validated) => {
        for warning in validated.warnings() {
            log::warn!("{}", warning);
        }
        let theme = validated.into_theme();
    }
    Err(errors) => {
        for error in errors {
            eprintln!("Error: {}", error);
        }
    }
}

Required Methods§

Source

fn validate(&self, raw: RawConfig) -> Result<ValidatedConfig, Vec<ConfigError>>

Validates raw configuration and returns a validated configuration.

§Arguments
  • raw — The raw configuration to validate
§Returns

A ValidatedConfig containing the theme and any warnings.

§Errors

Returns a vector of ConfigError if validation fails. Multiple errors may be returned to show all problems at once.

Source

fn validate_color(&self, value: &str, key: &str) -> Result<()>

Validates a single color value.

§Arguments
  • value — The color value to validate (e.g., “#1e1e2e”)
  • key — The configuration key for error reporting
§Errors

Returns ConfigError::InvalidColor if the value is not valid.

Source

fn validate_spacing(&self, value: u16, key: &str) -> Result<()>

Validates a spacing value.

§Arguments
  • value — The spacing value in pixels
  • key — The configuration key for error reporting
§Errors

Returns [ConfigError::InvalidValue] if the value is out of range.

Implementors§