pub struct EvaluationResult {
pub description: String,
pub mime_type: Option<String>,
pub confidence: f64,
pub matches: Vec<RuleMatch>,
pub metadata: EvaluationMetadata,
}Expand description
Result of magic rule evaluation
Contains the file type description, optional MIME type, confidence score, individual match details, and evaluation metadata.
§Relationship to crate::output::EvaluationResult
This is the library-facing result type returned by MagicDatabase::evaluate_file
and MagicDatabase::evaluate_buffer.
It carries a rolled-up description, MIME type, and confidence score along with
raw evaluator::RuleMatch values. It intentionally does not carry the
analyzed filename or a surface-level error string, because those are caller
concerns (a caller may evaluate an in-memory buffer that has no filename).
The parallel type crate::output::EvaluationResult is the output-facing
result used by the CLI and JSON/text formatters. It adds filename and
error, carries enriched crate::output::MatchResult values (with
extracted tags), and uses u32 counters in its metadata to match the JSON
output schema.
The two types are intentionally distinct — do not try to unify them.
Convert library → output explicitly via
crate::output::EvaluationResult::from_library_result, which is the single
named conversion point. Any drift between the two hierarchies should be
resolved there, not by back-channel field copying in call sites.
§Examples
use libmagic_rs::{EvaluationResult, EvaluationMetadata};
let result = EvaluationResult {
description: "ELF 64-bit executable".to_string(),
mime_type: Some("application/x-executable".to_string()),
confidence: 0.9,
matches: vec![],
metadata: EvaluationMetadata::default(),
};
assert_eq!(result.description, "ELF 64-bit executable");
assert!(result.confidence > 0.5);Fields§
§description: StringHuman-readable file type description
This is the concatenated message from all matching rules, following libmagic behavior where hierarchical matches are joined with spaces (unless backspace character is used).
mime_type: Option<String>Optional MIME type for the detected file type
Only populated when enable_mime_types is set in the configuration.
Omitted from the serialized form when unset (rather than emitted
as "mime_type": null) so downstream JSON consumers can treat
presence as the “MIME type is known” indicator.
confidence: f64Confidence score (0.0 to 1.0)
Based on the depth of the match in the rule hierarchy. Deeper matches indicate more specific identification.
matches: Vec<RuleMatch>Individual match results from rule evaluation
Contains details about each rule that matched, including offset, matched value, and per-match confidence.
metadata: EvaluationMetadataMetadata about the evaluation process
Trait Implementations§
Source§impl Clone for EvaluationResult
impl Clone for EvaluationResult
Source§fn clone(&self) -> EvaluationResult
fn clone(&self) -> EvaluationResult
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more