Struct vectorscan::expression::Literal
source · pub struct Literal(/* private fields */);
compiler
only.Expand description
A literal byte string.
Unlike for Expression
, Database::compile_literal()
will parse the
string content in a literal sense without any regular grammars. For example,
the expression abc?
simply means a char sequence of a
, b
, c
,
and ?
. The ?
here doesn’t mean 0 or 1 quantifier under regular
semantics.
Also unlike Expression
, the underlying vectorscan library interprets
literal patterns with a pointer and a length instead of a NULL
-terminated
string. Importantly, this allows it to contain \0
or NULL
bytes
itself!
Finally note that literal expressions do not support an “info” interface
like Expression::info()
and Expression::ext_info()
, since most of
those properties can be inferred from the literal string itself.
Instances can be created equivalently with Self::new()
or
str::parse()
via the str::FromStr
impl:
use vectorscan::expression::Literal;
let e1: Literal = "as\0df".parse()?;
let e2 = Literal::new("as\0df")?;
assert_eq!(e1, e2);
Implementations§
source§impl Literal
impl Literal
sourcepub fn as_bytes(&self) -> &[u8] ⓘ
pub fn as_bytes(&self) -> &[u8] ⓘ
Reference the underlying bytes. This wrapper does not allocate any null terminator.
let e = vectorscan::expression::Literal::new("as\0df")?;
assert_eq!(e.as_bytes(), b"as\0df");
sourcepub fn new(x: impl Into<Vec<u8>>) -> Result<Self, VectorscanCompileError>
pub fn new(x: impl Into<Vec<u8>>) -> Result<Self, VectorscanCompileError>
Wrap a byte slice to be interpreted literally. This does not allocate any null terminator.
sourcepub fn compile(
&self,
flags: Flags,
mode: Mode
) -> Result<Database, VectorscanCompileError>
pub fn compile( &self, flags: Flags, mode: Mode ) -> Result<Database, VectorscanCompileError>
Call Database::compile_literal()
with None
for the platform.
Trait Implementations§
source§impl Ord for Literal
impl Ord for Literal
source§impl PartialEq for Literal
impl PartialEq for Literal
source§impl PartialOrd for Literal
impl PartialOrd for Literal
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Literal
impl StructuralEq for Literal
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl RefUnwindSafe for Literal
impl Send for Literal
impl Sync for Literal
impl Unpin for Literal
impl UnwindSafe for Literal
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.