Skip to main content

RunRule

Struct RunRule 

Source
pub struct RunRule {
    pub cur: ByteSet,
    pub class: RunClass,
    pub min: u8,
    pub max: u8,
    pub lengths: u64,
    pub after: ByteSet,
    pub after_end: bool,
    pub then: [Option<Then>; 2],
}
Expand description

A declarative rule on the run starting at a candidate position, see Finder::run_rules.

A rule applies when the start byte is in cur; it accepts when the class run has a length in min..=max (and in lengths when set), the byte after it is in after (or the input ends there and after_end is set), and every Then step is met in turn right after that byte (an IPv4 address starts with 1.2. whatever follows, a MAC address with aa:bb:cc:). A capped run always satisfies the rest of the rule, since its true end is unknown.

Fields§

§cur: ByteSet§class: RunClass§min: u8§max: u8§lengths: u64

Bit n set: a run of n bytes is accepted; zero means every length in min..=max. Lengths of 64 and more are governed by min..=max alone.

§after: ByteSet§after_end: bool§then: [Option<Then>; 2]

Implementations§

Source§

impl RunRule

Source

pub fn new(class: RunClass, min: u8, max: u8) -> RunRule

A rule for class runs of min..=max bytes starting at any byte of the class and followed by any byte, including the end of the input.

Source

pub fn lengths(self, lengths: u64) -> RunRule

Restricts the rule’s own run to the lengths whose bit is set in lengths (bit n for n bytes), within min..=max.

Source

pub fn followed_by(self, bytes: &[u8]) -> RunRule

Requires the byte after the last run described so far (the rule’s own run, or its latest then step) to be one of bytes; the end of the input no longer qualifies unless or_end follows.

Source

pub fn followed_by_set(self, set: ByteSet) -> RunRule

Like followed_by with a byte set.

Source

pub fn or_end(self) -> RunRule

Also accepts the end of the input after the last run described so far.

Source

pub fn then(self, class: RunClass, min: u8, max: u8) -> RunRule

Chains a run of class bytes numbering min..=max that must start right after the byte ending the previous run; it may be followed by anything until followed_by restricts it. Up to MAX_THEN steps can be chained. As for the first run, a max of RUN_CAP means unbounded.

Source

pub fn allow( rules: &[RunRule], cur: u8, runs: &Runs, input: &[u8], pos: usize, ) -> bool

Evaluates a finder’s rules for the candidate at pos of input, whose runs are runs: a match may start when no rule applies to cur, or when at least one applicable rule accepts.

Trait Implementations§

Source§

impl Clone for RunRule

Source§

fn clone(&self) -> Self

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 Copy for RunRule

Source§

impl Debug for RunRule

Source§

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

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

impl Eq for RunRule

Source§

impl PartialEq for RunRule

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for RunRule

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.