Skip to main content

RegexFlags

Struct RegexFlags 

Source
pub struct RegexFlags {
    pub case_insensitive: bool,
    pub start_offset: bool,
}
Expand description

Regex modifier flags parsed from the /[cs] suffix on a regex rule.

The /l “line-based window” modifier is not represented here; it lives on RegexCount::Lines so that the type-level encoding makes “line count” and “byte count” mutually exclusive. An earlier design used two separate fields (line_based: bool + count: Option<u32>) which admitted the cross-field state line_based: true, count: None; under the current encoding that case is expressed explicitly as RegexCount::Lines(None) – the regex/l shorthand – and is behaviorally equivalent to RegexCount::Default (both walk the full 8192-byte capped window).

All flags default to false via RegexFlags::default, equivalent to a plain regex with no /c or /s suffix.

§Examples

use libmagic_rs::parser::ast::RegexFlags;

let plain = RegexFlags::default();
assert!(!plain.case_insensitive);
assert!(!plain.start_offset);

let case_and_start = RegexFlags::default()
    .with_case_insensitive(true)
    .with_start_offset(true);
assert!(case_and_start.case_insensitive);
assert!(case_and_start.start_offset);

Fields§

§case_insensitive: bool

/c – case-insensitive matching. When true, ASCII letter casing is ignored during pattern matching.

§start_offset: bool

/s – advance the GNU file previous-match anchor to the start of the matched region instead of its end. Matches libmagic’s REGEX_OFFSET_START flag, which zeros the length contribution in moffset() for FILE_REGEX. Useful for chaining child rules that need to re-match from the position where the parent regex began.

Implementations§

Source§

impl RegexFlags

Source

pub const fn with_case_insensitive(self, value: bool) -> Self

Builder-style setter for RegexFlags::case_insensitive (/c).

Chain after RegexFlags::default() to construct RegexFlags values without exhaustive struct literals. If a new flag is added to RegexFlags in the future, callers using the builder form keep compiling; callers using struct literals would need an update.

Source

pub const fn with_start_offset(self, value: bool) -> Self

Builder-style setter for RegexFlags::start_offset (/s).

Chain after RegexFlags::default() to construct RegexFlags values without exhaustive struct literals.

Trait Implementations§

Source§

impl Clone for RegexFlags

Source§

fn clone(&self) -> RegexFlags

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 RegexFlags

Source§

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

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

impl Default for RegexFlags

Source§

fn default() -> RegexFlags

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for RegexFlags

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for RegexFlags

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for RegexFlags

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
Source§

impl Copy for RegexFlags

Source§

impl Eq for RegexFlags

Source§

impl StructuralPartialEq for RegexFlags

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.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,