#[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 leastvalue#[validate(max(value))]- Validates that the field value is at mostvalue#[validate(optional_range(min, max))]- Likerange, but forOption<T>fields (only validates if Some)#[validate(path)]- Validates that the path exists (for PathBuf fields)#[validate(optional_path)]- Likepath, but forOption<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>,
}