pub struct Literal { /* private fields */ }
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.)

Implementations

Returns a new exact literal containing the bytes given.

Returns a new inexact literal containing the bytes given.

Returns the bytes in this literal.

Yields ownership of the bytes inside this literal.

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

Returns the length of this literal in bytes.

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

Returns true if and only if this literal is exact.

Marks this literal as inexact.

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

Reverse the bytes in this literal.

Extend this literal with the literal given.

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

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.

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.

Trait Implementations

Converts this type into a shared reference of the (usually inferred) input type.
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Creates a value from an iterator. Read more
This method returns an Ordering between self and other. Read more
Compares and returns the maximum of two values. Read more
Compares and returns the minimum of two values. Read more
Restrict a value to a certain interval. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
This method returns an ordering between self and other values if one exists. Read more
This method tests less than (for self and other) and is used by the < operator. Read more
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
This method tests greater than (for self and other) and is used by the > operator. Read more
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.