Skip to main content

EvaluationResult

Struct EvaluationResult 

Source
#[non_exhaustive]
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::new(
    "ELF 64-bit executable".to_string(),
    Some("application/x-executable".to_string()),
    0.9,
    vec![],
    EvaluationMetadata::default(),
);

assert_eq!(result.description, "ELF 64-bit executable");
assert!(result.confidence > 0.5);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§description: String

Human-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: f64

Confidence 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: EvaluationMetadata

Metadata about the evaluation process

Implementations§

Source§

impl EvaluationResult

Source

pub fn new( description: String, mime_type: Option<String>, confidence: f64, matches: Vec<RuleMatch>, metadata: EvaluationMetadata, ) -> Self

Construct a new library-side EvaluationResult.

This is the outbound type returned by MagicDatabase::evaluate_file and MagicDatabase::evaluate_buffer. For the output-facing type used by the CLI and JSON/text formatters, see crate::output::EvaluationResult::from_library_result.

Trait Implementations§

Source§

impl Clone for EvaluationResult

Source§

fn clone(&self) -> EvaluationResult

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for EvaluationResult

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Serialize for EvaluationResult

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.