Skip to main content

format_evaluation_result

Function format_evaluation_result 

Source
pub fn format_evaluation_result(evaluation: &EvaluationResult) -> String
Expand description

Format an evaluation result as text with filename

Formats a complete evaluation result in the style of the GNU file command, including the filename followed by a colon and the formatted match results.

§Arguments

  • evaluation - The evaluation result to format

§Returns

A formatted string in the format “filename: description”

§Examples

use libmagic_rs::output::{EvaluationResult, MatchResult, EvaluationMetadata, text::format_evaluation_result};
use libmagic_rs::parser::ast::Value;
use std::path::PathBuf;

let result = MatchResult::new(
    "PNG image data".to_string(),
    0,
    Value::Bytes(vec![0x89, 0x50, 0x4e, 0x47])
);

let metadata = EvaluationMetadata::new(2048, 1.5, 10, 1);
let evaluation = EvaluationResult::new(
    PathBuf::from("image.png"),
    vec![result],
    metadata
);

let formatted = format_evaluation_result(&evaluation);
assert_eq!(formatted, "image.png: PNG image data");