Skip to main content

EvaluationContext

Struct EvaluationContext 

Source
pub struct EvaluationContext { /* private fields */ }
Expand description

Context for maintaining evaluation state during rule processing

The EvaluationContext tracks the current state of rule evaluation, including the current offset position, recursion depth for nested rules, and configuration settings that control evaluation behavior.

§Examples

use libmagic_rs::evaluator::EvaluationContext;
use libmagic_rs::EvaluationConfig;

let config = EvaluationConfig::default();
let context = EvaluationContext::new(config);

assert_eq!(context.current_offset(), 0);
assert_eq!(context.recursion_depth(), 0);

Implementations§

Source§

impl EvaluationContext

Source

pub const fn new(config: EvaluationConfig) -> Self

Create a new evaluation context with the given configuration

§Arguments
  • config - Configuration settings for evaluation behavior
§Examples
use libmagic_rs::evaluator::EvaluationContext;
use libmagic_rs::EvaluationConfig;

let config = EvaluationConfig::default();
let context = EvaluationContext::new(config);
Source

pub const fn current_offset(&self) -> usize

Get the current offset position

§Returns

The current offset position in the file buffer

Source

pub fn set_current_offset(&mut self, offset: usize)

Set the current offset position

§Arguments
  • offset - The new offset position
Source

pub const fn recursion_depth(&self) -> u32

Get the current recursion depth

§Returns

The current recursion depth for nested rule evaluation

Source

pub fn increment_recursion_depth(&mut self) -> Result<(), LibmagicError>

Increment the recursion depth

§Returns

Ok(()) if the recursion depth is within limits, or Err(LibmagicError) if the maximum recursion depth would be exceeded

§Errors

Returns LibmagicError::EvaluationError if incrementing would exceed the maximum recursion depth configured in the evaluation config.

Source

pub fn decrement_recursion_depth(&mut self) -> Result<(), LibmagicError>

Decrement the recursion depth

§Errors

Returns an error if the recursion depth is already 0, as this indicates a programming error in the evaluation logic (mismatched increment/decrement calls).

Source

pub const fn config(&self) -> &EvaluationConfig

Get a reference to the evaluation configuration

§Returns

A reference to the EvaluationConfig used by this context

Source

pub const fn should_stop_at_first_match(&self) -> bool

Check if evaluation should stop at the first match

§Returns

true if evaluation should stop at the first match, false otherwise

Source

pub const fn max_string_length(&self) -> usize

Get the maximum string length allowed

§Returns

The maximum string length that should be read during evaluation

Source

pub const fn enable_mime_types(&self) -> bool

Check if MIME type mapping is enabled

§Returns

true if MIME type mapping should be performed, false otherwise

Source

pub const fn timeout_ms(&self) -> Option<u64>

Get the evaluation timeout in milliseconds

§Returns

The timeout duration in milliseconds, or None if no timeout is set

Source

pub fn reset(&mut self)

Reset the context to initial state while preserving configuration

This resets the current offset and recursion depth to 0, but keeps the same configuration settings.

Trait Implementations§

Source§

impl Clone for EvaluationContext

Source§

fn clone(&self) -> EvaluationContext

Returns a duplicate of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for EvaluationContext

Source§

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

Formats the value using the given formatter. 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.