ResultFormatter

Trait ResultFormatter 

Source
pub trait ResultFormatter {
    // Required method
    fn format(&self, result: &ValidationResult) -> Result<String>;

    // Provided method
    fn format_with_config(
        &self,
        result: &ValidationResult,
        _config: &FormatterConfig,
    ) -> Result<String> { ... }
}
Expand description

Trait for formatting validation results into different output formats.

This trait provides a uniform interface for converting validation results into various formats like JSON, human-readable text, or Markdown.

§Examples

use term_guard::formatters::{ResultFormatter, JsonFormatter};
use term_guard::core::ValidationResult;

struct MyCustomFormatter;

impl ResultFormatter for MyCustomFormatter {
    fn format(&self, result: &ValidationResult) -> term_guard::prelude::Result<String> {
        let success = result.is_success();
        Ok(format!("Custom format: {success}"))
    }
}

Required Methods§

Source

fn format(&self, result: &ValidationResult) -> Result<String>

Formats a validation result into a string representation.

§Arguments
  • result - The validation result to format
§Returns

A formatted string representation of the result

Provided Methods§

Source

fn format_with_config( &self, result: &ValidationResult, _config: &FormatterConfig, ) -> Result<String>

Formats a validation result with custom configuration.

§Arguments
  • result - The validation result to format
  • config - Configuration options for formatting
§Returns

A formatted string representation of the result

Implementors§