Skip to main content

format_text_output

Function format_text_output 

Source
pub fn format_text_output(results: &[MatchResult]) -> String
Expand description

Format multiple match results as concatenated text

Combines multiple match results into a single text string, with messages separated by commas and spaces. This follows the GNU file command convention of showing hierarchical matches in a single line.

§Arguments

  • results - Vector of match results to format

§Returns

A formatted string with all match messages concatenated

§Examples

use libmagic_rs::output::{MatchResult, text::format_text_output};
use libmagic_rs::parser::ast::Value;

let results = vec![
    MatchResult::new(
        "ELF 64-bit LSB executable".to_string(),
        0,
        Value::Bytes(vec![0x7f, 0x45, 0x4c, 0x46])
    ),
    MatchResult::new(
        "x86-64".to_string(),
        18,
        Value::Uint(0x3e)
    ),
    MatchResult::new(
        "dynamically linked".to_string(),
        16,
        Value::Uint(0x02)
    ),
];

let formatted = format_text_output(&results);
assert_eq!(formatted, "ELF 64-bit LSB executable, x86-64, dynamically linked");