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:
| Category | Validation |
|---|---|
| Colors | Valid hex format, correct length |
| Numbers | Within valid ranges |
| Strings | Non-empty where required |
| Structure | Required fields present |
| Keys | Warning 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§
Sourcefn validate(&self, raw: RawConfig) -> Result<ValidatedConfig, Vec<ConfigError>>
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.
Sourcefn validate_color(&self, value: &str, key: &str) -> Result<()>
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.