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 PartialOrd for Literal
impl PartialOrd for Literal
impl Eq for Literal
impl StructuralPartialEq for Literal
Auto Trait Implementations§
impl Freeze for Literal
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 32 bytes