#[non_exhaustive]pub enum ValueTransformOp {
Add,
Sub,
Mul,
Div,
Mod,
BitAnd,
Or,
Xor,
}Expand description
Arithmetic operation applied to a value read from the file before the rule’s comparison operator is evaluated.
magic(5) supports +, -, *, /, %, |, and ^ between the type
keyword and the comparison value (e.g., lelong+1 x volume %d reads a
long, adds 1, and formats the transformed value into the message).
Bitwise AND (&MASK) is not part of this enum because it is already
represented at the operator level via Operator::BitwiseAndMask.
The operand is signed (i64) so that subtraction and negative multipliers
round-trip cleanly. Bitwise ops reinterpret the operand as a u64 bit
pattern at evaluation time, matching libmagic’s apprentice.c::mconvert.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Add
Addition (type+N).
Sub
Subtraction (type-N).
Mul
Multiplication (type*N).
Div
Truncating integer division (type/N). Division by zero is rejected
at evaluation time.
Mod
Remainder (type%N). Modulo by zero is rejected at evaluation time.
BitAnd
Bitwise AND (type&N).
magic(5) &MASK was historically encoded at the operator level
via Operator::BitwiseAndMask (which combines mask+equal in
one step). That encoding cannot represent rules like lelong&0xff x %d (mask + any-value, with the masked value used in format
substitution). The parser promotes &MASK to this BitAnd
transform when followed by another operator (x, >, !=, …)
so the read value is masked before comparison and before printf
substitution. The legacy &MASK VALUE form (mask + implicit
equal) keeps using Operator::BitwiseAndMask for backwards
compatibility.
Or
Bitwise OR (type|N).
Xor
Bitwise XOR (type^N).
Trait Implementations§
Source§impl Clone for ValueTransformOp
impl Clone for ValueTransformOp
Source§fn clone(&self) -> ValueTransformOp
fn clone(&self) -> ValueTransformOp
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more