pub struct RuleMatch {
pub message: String,
pub offset: usize,
pub level: u32,
pub value: Value,
pub confidence: f64,
}Expand description
Result of evaluating a magic rule
Contains information about a successful rule match, including the rule that matched and its associated message.
Fields§
§message: StringThe message associated with the matching rule
offset: usizeThe offset where the match occurred
level: u32The rule level (depth in hierarchy)
value: ValueThe matched value
confidence: f64Confidence score (0.0 to 1.0)
Calculated based on match depth in the rule hierarchy. Deeper matches indicate more specific file type identification and thus higher confidence.
Implementations§
Source§impl RuleMatch
impl RuleMatch
Sourcepub fn calculate_confidence(level: u32) -> f64
pub fn calculate_confidence(level: u32) -> f64
Calculate confidence score based on rule depth
Formula: min(1.0, 0.3 + (level * 0.2))
- Level 0 (root): 0.3
- Level 1: 0.5
- Level 2: 0.7
- Level 3: 0.9
- Level 4+: 1.0 (capped)
§Examples
use libmagic_rs::evaluator::RuleMatch;
assert!((RuleMatch::calculate_confidence(0) - 0.3).abs() < 0.001);
assert!((RuleMatch::calculate_confidence(3) - 0.9).abs() < 0.001);
assert!((RuleMatch::calculate_confidence(10) - 1.0).abs() < 0.001);Trait Implementations§
Source§impl<'de> Deserialize<'de> for RuleMatch
impl<'de> Deserialize<'de> for RuleMatch
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
impl StructuralPartialEq for RuleMatch
Auto Trait Implementations§
impl Freeze for RuleMatch
impl RefUnwindSafe for RuleMatch
impl Send for RuleMatch
impl Sync for RuleMatch
impl Unpin for RuleMatch
impl UnsafeUnpin for RuleMatch
impl UnwindSafe for RuleMatch
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more