ConfigValidator

Derive Macro ConfigValidator 

Source
#[derive(ConfigValidator)]
{
    // Attributes available to this derive:
    #[validate]
}
Expand description

Derive macro for implementing ConfigValidator trait.

This macro generates a ConfigValidator implementation for configuration structs. Validation rules are specified using the #[validate(...)] attribute on fields.

§Supported Validators

  • #[validate(range(min, max))] - Validates that the field value is within the inclusive range [min, max]
  • #[validate(min(value))] - Validates that the field value is at least value
  • #[validate(max(value))] - Validates that the field value is at most value
  • #[validate(optional_range(min, max))] - Like range, but for Option<T> fields (only validates if Some)
  • #[validate(path)] - Validates that the path exists (for PathBuf fields)
  • #[validate(optional_path)] - Like path, but for Option<PathBuf> fields

§Example

use oar_ocr_derive::ConfigValidator;

#[derive(ConfigValidator, Default)]
pub struct TextDetectionConfig {
    #[validate(range(0.0, 1.0))]
    pub score_threshold: f32,

    #[validate(range(0.0, 1.0))]
    pub box_threshold: f32,

    #[validate(min(0.0))]
    pub unclip_ratio: f32,

    #[validate(min(1))]
    pub max_candidates: usize,

    // Fields without #[validate] are not validated
    pub limit_side_len: Option<u32>,
}