Skip to main content

RegexBuf

Struct RegexBuf 

Source
pub struct RegexBuf<const N: usize = DEFAULT_NODES, const CCL: usize = DEFAULT_CCL, const MEMO: usize = DEFAULT_MEMO> { /* private fields */ }
Expand description

An owned, compiled regex pattern with compile-time-fixed storage.

  • N — node capacity: max compiled pattern symbols.
  • CCL — character-class buffer size in bytes.
  • MEMO — memo table size in bytes; use (N * DEFAULT_MATCH_TEXT_LEN + 7) / 8.

For the common case use Regex (a type alias for RegexBuf<32, 64, 256>) so you never spell out the parameters. Use RegexBuf directly only when you need non-default sizes.

Created via RegexBuf::new; the pattern can be updated in-place via RegexBuf::recompile. Use find_at and find_iter to search.

A RegexBuf is always valid — construction fails explicitly via None. Each find_at call stack-allocates and zeros a [u8; MEMO] memo table independently, so RegexBuf is Send + Sync without unsafe.

Implementations§

Source§

impl<const N: usize, const CCL: usize, const MEMO: usize> RegexBuf<N, CCL, MEMO>

Source

pub fn find_at<'a>(&self, haystack: &'a CStr, start: usize) -> Option<Match<'a>>

Search haystack for the first match of this pattern at or after byte offset start.

Returns None if no match is found. Each call stack-allocates a zero-initialised memo table to cache failed (pattern_node, text_offset) states and eliminate exponential backtracking.

Source

pub fn find_iter<'a, 'b>( &'a self, haystack: &'b CStr, ) -> Matches<'a, 'b, N, CCL, MEMO>

Return an iterator over all non-overlapping matches in haystack.

Source§

impl<const N: usize, const CCL: usize, const MEMO: usize> RegexBuf<N, CCL, MEMO>

Source

pub fn new(pattern: &CStr) -> Option<RegexBuf<N, CCL, MEMO>>

Compile pattern into a new RegexBuf.

Returns None if pattern is syntactically invalid or exceeds the node capacity N or character-class buffer CCL.

Source

pub fn recompile(self, pattern: &CStr) -> Option<RegexBuf<N, CCL, MEMO>>

Recompile this RegexBuf with a new pattern, reusing existing storage.

Returns Some on success. On failure returns None and self is dropped — the previous compiled pattern is lost.

Auto Trait Implementations§

§

impl<const N: usize, const CCL: usize, const MEMO: usize> Freeze for RegexBuf<N, CCL, MEMO>

§

impl<const N: usize, const CCL: usize, const MEMO: usize> RefUnwindSafe for RegexBuf<N, CCL, MEMO>

§

impl<const N: usize, const CCL: usize, const MEMO: usize> Send for RegexBuf<N, CCL, MEMO>

§

impl<const N: usize, const CCL: usize, const MEMO: usize> Sync for RegexBuf<N, CCL, MEMO>

§

impl<const N: usize, const CCL: usize, const MEMO: usize> Unpin for RegexBuf<N, CCL, MEMO>

§

impl<const N: usize, const CCL: usize, const MEMO: usize> UnsafeUnpin for RegexBuf<N, CCL, MEMO>

§

impl<const N: usize, const CCL: usize, const MEMO: usize> UnwindSafe for RegexBuf<N, CCL, MEMO>

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> 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, 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.