Skip to main content

Grep

Struct Grep 

Source
pub struct Grep<'a> { /* private fields */ }
Expand description

What one ARGREP was asked to look for.

Built once per command and then asked about every element the walk visits, which is why the compiled regexes and the matcher’s scratch space live here rather than being made per element.

§This one allocates

Every other command path here is allocation free, and ARGREP cannot be: compiling a regular expression means building a program, and the plan holds up to two hundred and fifty predicates. Redis allocates in the same two places for the same reasons. The allocations are wrapped in yo_alloc::allow and they all happen while the command is being read, so the walk itself is still allocation free however many elements it visits.

Implementations§

Source§

impl<'a> Grep<'a>

Source

pub fn new() -> Grep<'a>

An empty plan, which is not a usable one until it has been told what to look for and then Grep::compiled.

Source

pub fn push(&mut self, test: Test, pattern: &'a [u8]) -> Result<()>

Adds one predicate in the order it was written.

§Errors

Code::Invalid once there are GREP_MAX_PREDICATES of them, or for an RE pattern longer than GREP_MAX_RE_LEN. Both are checked here rather than at the end because Redis checks them as it reads, so a command that is wrong in two ways reports whichever comes first.

Source

pub fn len(&self) -> usize

How many predicates the plan carries, since none at all is a syntax error and the caller is the one that says so.

Source

pub fn is_empty(&self) -> bool

Whether nothing has been asked for yet.

Source

pub fn compile(&mut self, all: bool, nocase: bool) -> Result<()>

Settles the two global options and compiles the regular expressions.

The compile is deliberately the last thing that happens while the command is being read, because NOCASE is a global option that may come after the pattern it applies to.

§Errors

Code::Invalid with the sentence Redis uses for an empty pattern, a pattern that will not compile, or a pattern using a backreference.

Trait Implementations§

Source§

impl Default for Grep<'_>

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl<'a> Freeze for Grep<'a>

§

impl<'a> RefUnwindSafe for Grep<'a>

§

impl<'a> Send for Grep<'a>

§

impl<'a> Sync for Grep<'a>

§

impl<'a> Unpin for Grep<'a>

§

impl<'a> UnsafeUnpin for Grep<'a>

§

impl<'a> UnwindSafe for Grep<'a>

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

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.