check_limits

Function check_limits 

Source
pub fn check_limits(args: &Cli, total: &Count) -> Result<(), Vec<String>>
Expand description

Checks if word and character counts are within specified limits.

Validates that the total counts meet any minimum or maximum limits specified in the CLI arguments. This is useful for CI/CD pipelines to enforce document length requirements.

§Arguments

  • args - Command-line arguments containing limit specifications
  • total - The total count to check against limits

§Returns

  • Ok(()) if all limits are satisfied
  • Err(Vec<String>) containing error messages for each violated limit

§Limit Checks

The following limits are checked if specified:

  • max_words - Maximum allowed word count
  • min_words - Minimum required word count
  • max_characters - Maximum allowed character count
  • min_characters - Minimum required character count

§Examples

use typst_count::{check_limits, cli::Cli, counter::Count};
use clap::Parser;

let args = Cli::parse();
let total = Count { words: 500, characters: 2500 };

match check_limits(&args, &total) {
    Ok(()) => println!("All limits satisfied"),
    Err(errors) => {
        for error in errors {
            eprintln!("Limit violation: {}", error);
        }
    }
}