Struct regex_syntax::hir::literal::Literal
source · 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§
source§impl Literal
impl Literal
sourcepub fn exact<B: Into<Vec<u8>>>(bytes: B) -> Literal
pub fn exact<B: Into<Vec<u8>>>(bytes: B) -> Literal
Returns a new exact literal containing the bytes given.
sourcepub fn inexact<B: Into<Vec<u8>>>(bytes: B) -> Literal
pub fn inexact<B: Into<Vec<u8>>>(bytes: B) -> Literal
Returns a new inexact literal containing the bytes given.
sourcepub fn into_bytes(self) -> Vec<u8>
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.
sourcepub fn make_inexact(&mut self)
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.
sourcepub fn extend(&mut self, lit: &Literal)
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.
sourcepub fn keep_first_bytes(&mut self, len: usize)
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.
sourcepub fn keep_last_bytes(&mut self, len: usize)
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.
Trait Implementations§
source§impl FromIterator<Literal> for Seq
impl FromIterator<Literal> for Seq
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 more