pub struct Literal {
    bytes: Vec<u8>,
    exact: bool,
}
Expand description

A single literal extracted from an Hir expression.

A literal is composed of two things:

  • A sequence of bytes. No guarantees with respect to UTF-8 are provided. In particular, even if the regex a literal is extracted from is UTF-8, the literal extracted may not be valid UTF-8. (For example, if an Extractor limit resulted in trimming a literal in a way that splits a codepoint.)
  • Whether the literal is “exact” or not. An “exact” literal means that it has not been trimmed, and may continue to be extended. If a literal is “exact” after visiting the entire Hir expression, then this implies that the literal leads to a match state. (Although it doesn’t necessarily imply all occurrences of the literal correspond to a match of the regex, since literal extraction ignores look-around assertions.)

Fields§

§bytes: Vec<u8>§exact: bool

Implementations§

source§

impl Literal

source

pub fn exact<B: Into<Vec<u8>>>(bytes: B) -> Literal

Returns a new exact literal containing the bytes given.

source

pub fn inexact<B: Into<Vec<u8>>>(bytes: B) -> Literal

Returns a new inexact literal containing the bytes given.

source

pub fn as_bytes(&self) -> &[u8]

Returns the bytes in this literal.

source

pub fn into_bytes(self) -> Vec<u8>

Yields ownership of the bytes inside this literal.

Note that this throws away whether the literal is “exact” or not.

source

pub fn len(&self) -> usize

Returns the length of this literal in bytes.

source

pub fn is_empty(&self) -> bool

Returns true if and only if this literal has zero bytes.

source

pub fn is_exact(&self) -> bool

Returns true if and only if this literal is exact.

source

pub fn make_inexact(&mut self)

Marks this literal as inexact.

Inexact literals can never be extended. For example, Seq::cross_forward will not extend inexact literals.

source

pub fn reverse(&mut self)

Reverse the bytes in this literal.

source

pub fn extend(&mut self, lit: &Literal)

Extend this literal with the literal given.

If this literal is inexact, then this is a no-op.

source

pub fn keep_first_bytes(&mut self, len: usize)

Trims this literal such that only the first len bytes remain. If this literal has fewer than len bytes, then it remains unchanged. Otherwise, the literal is marked as inexact.

source

pub fn keep_last_bytes(&mut self, len: usize)

Trims this literal such that only the last len bytes remain. If this literal has fewer than len bytes, then it remains unchanged. Otherwise, the literal is marked as inexact.

source

fn is_poisonous(&self) -> bool

Returns true if it is believe that this literal is likely to match very frequently, and is thus not a good candidate for a prefilter.

Trait Implementations§

source§

impl AsRef<[u8]> for Literal

source§

fn as_ref(&self) -> &[u8]

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl Clone for Literal

source§

fn clone(&self) -> Literal

Returns a copy 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 Literal

source§

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

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

impl From<char> for Literal

source§

fn from(ch: char) -> Literal

Converts to this type from the input type.
source§

impl From<u8> for Literal

source§

fn from(byte: u8) -> Literal

Converts to this type from the input type.
source§

impl FromIterator<Literal> for Seq

source§

fn from_iter<T: IntoIterator<Item = Literal>>(it: T) -> Seq

Creates a value from an iterator. Read more
source§

impl Ord for Literal

source§

fn cmp(&self, other: &Literal) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl PartialEq<Literal> for Literal

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd<Literal> for Literal

source§

fn partial_cmp(&self, other: &Literal) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Eq for Literal

source§

impl StructuralEq for Literal

source§

impl StructuralPartialEq for Literal

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

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 Twhere U: TryFrom<T>,

§

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.