ConfigValidator

Trait ConfigValidator 

Source
pub trait ConfigValidator {
    // Required methods
    fn validate(&self) -> Result<(), ConfigError>;
    fn get_defaults() -> Self
       where Self: Sized;

    // Provided methods
    fn validate_batch_size(&self, batch_size: usize) -> Result<(), ConfigError> { ... }
    fn validate_batch_size_with_limits(
        &self,
        batch_size: usize,
        max_batch_size: usize,
    ) -> Result<(), ConfigError> { ... }
    fn validate_model_path(&self, path: &Path) -> Result<(), ConfigError> { ... }
    fn validate_image_dimensions(
        &self,
        width: u32,
        height: u32,
    ) -> Result<(), ConfigError> { ... }
    fn validate_confidence_threshold(
        &self,
        threshold: f32,
    ) -> Result<(), ConfigError> { ... }
    fn validate_memory_limit(&self, limit_mb: usize) -> Result<(), ConfigError> { ... }
    fn validate_thread_count(
        &self,
        thread_count: usize,
    ) -> Result<(), ConfigError> { ... }
    fn validate_f32_range(
        &self,
        value: f32,
        min: f32,
        max: f32,
        field_name: &str,
    ) -> Result<(), ConfigError> { ... }
    fn validate_positive_f32(
        &self,
        value: f32,
        field_name: &str,
    ) -> Result<(), ConfigError> { ... }
    fn validate_positive_usize(
        &self,
        value: usize,
        field_name: &str,
    ) -> Result<(), ConfigError> { ... }
}
Expand description

A trait for validating configuration parameters.

This trait provides methods for validating various configuration parameters used in the OCR pipeline, such as batch sizes, model paths, and image dimensions.

Required Methods§

Source

fn validate(&self) -> Result<(), ConfigError>

Validates the configuration.

This method should be implemented by types that need to validate their configuration.

§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn get_defaults() -> Self
where Self: Sized,

Returns the default configuration.

This method should be implemented by types that have default configuration values.

§Returns

The default configuration.

Provided Methods§

Source

fn validate_batch_size(&self, batch_size: usize) -> Result<(), ConfigError>

Validates a batch size.

This method checks that the batch size is greater than 0.

§Arguments
  • batch_size - The batch size to validate.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_batch_size_with_limits( &self, batch_size: usize, max_batch_size: usize, ) -> Result<(), ConfigError>

Validates a batch size against limits.

This method checks that the batch size is greater than 0 and does not exceed the maximum allowed batch size.

§Arguments
  • batch_size - The batch size to validate.
  • max_batch_size - The maximum allowed batch size.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_model_path(&self, path: &Path) -> Result<(), ConfigError>

Validates a model path.

This method checks that the model path exists and is a file.

§Arguments
  • path - The path to validate.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_image_dimensions( &self, width: u32, height: u32, ) -> Result<(), ConfigError>

Validates image dimensions.

This method checks that image dimensions are positive.

§Arguments
  • width - The width to validate.
  • height - The height to validate.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_confidence_threshold( &self, threshold: f32, ) -> Result<(), ConfigError>

Validates a confidence threshold.

This method checks that the confidence threshold is between 0.0 and 1.0.

§Arguments
  • threshold - The threshold to validate.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_memory_limit(&self, limit_mb: usize) -> Result<(), ConfigError>

Validates a memory limit.

This method checks that the memory limit is reasonable.

§Arguments
  • limit_mb - The memory limit in megabytes to validate.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_thread_count(&self, thread_count: usize) -> Result<(), ConfigError>

Validates thread count.

This method checks that the thread count is reasonable.

§Arguments
  • thread_count - The thread count to validate.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_f32_range( &self, value: f32, min: f32, max: f32, field_name: &str, ) -> Result<(), ConfigError>

Validates a float value is within a specified range.

§Arguments
  • value - The value to validate.
  • min - The minimum allowed value (inclusive).
  • max - The maximum allowed value (inclusive).
  • field_name - The name of the field being validated.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_positive_f32( &self, value: f32, field_name: &str, ) -> Result<(), ConfigError>

Validates a float value is positive.

§Arguments
  • value - The value to validate.
  • field_name - The name of the field being validated.
§Returns

A Result indicating success or a ConfigError if validation fails.

Source

fn validate_positive_usize( &self, value: usize, field_name: &str, ) -> Result<(), ConfigError>

Validates a usize value is positive.

§Arguments
  • value - The value to validate.
  • field_name - The name of the field being validated.
§Returns

A Result indicating success or a ConfigError if validation fails.

Implementations on Foreign Types§

Source§

impl ConfigValidator for Box<dyn ErasedConfig>

Implementors§