Struct Literal
pub struct Literal { /* private fields */ }
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
Extractorlimit 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
Hirexpression, 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
impl Literal
fn exact<B: Into<Vec<u8>>>(bytes: B) -> LiteralReturns a new exact literal containing the bytes given.
fn inexact<B: Into<Vec<u8>>>(bytes: B) -> LiteralReturns a new inexact literal containing the bytes given.
fn as_bytes(&self) -> &[u8]Returns the bytes in this literal.
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.
fn len(&self) -> usizeReturns the length of this literal in bytes.
fn is_empty(&self) -> boolReturns true if and only if this literal has zero bytes.
fn is_exact(&self) -> boolReturns true if and only if this literal is exact.
fn make_inexact(&mut self)Marks this literal as inexact.
Inexact literals can never be extended. For example,
Seq::cross_forwardwill not extend inexact literals.fn reverse(&mut self)Reverse the bytes in this literal.
fn extend(&mut self, lit: &Literal)Extend this literal with the literal given.
If this literal is inexact, then this is a no-op.
fn keep_first_bytes(&mut self, len: usize)Trims this literal such that only the first
lenbytes remain. If this literal has fewer thanlenbytes, then it remains unchanged. Otherwise, the literal is marked as inexact.fn keep_last_bytes(&mut self, len: usize)Trims this literal such that only the last
lenbytes remain. If this literal has fewer thanlenbytes, then it remains unchanged. Otherwise, the literal is marked as inexact.
Trait Implementations
impl AsRef<[u8]> for Literal
fn as_ref(&self) -> &[u8]
impl Clone for Literal
fn clone(&self) -> Self
impl Debug for Literal
fn fmt(&self, f: &mut Formatter<'_>) -> Result
impl Eq for Literal
impl From<char> for Literal
fn from(ch: char) -> Literal
impl From<u8> for Literal
fn from(byte: u8) -> Literal
impl Ord for Literal
fn cmp(&self, other: &Self) -> Ordering
impl PartialEq for Literal
fn eq(&self, other: &Self) -> bool
impl PartialOrd for Literal
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
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 UnsafeUnpin for Literal
impl UnwindSafe for Literal
Blanket Implementations
impl<T> Any for Literal
where
T: 'static + ?Sized,
fn type_id(&self) -> TypeId
impl<T> Borrow<T> for Literal
where
T: ?Sized,
fn borrow(&self) -> &T
impl<T> BorrowMut<T> for Literal
where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
impl<T> CloneToUninit for Literal
where
T: Clone,
unsafe fn clone_to_uninit(&self, dest: *mut u8)
impl<T> From<T> for Literal
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Literal
where
T: Clone,
type Owned = T;fn to_owned(&self) -> Tfn clone_into(&self, target: &mut T)
impl<T, U> Into<U> for Literal
where
U: From<T>,
fn into(self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom<U> for Literal
where
U: Into<T>,
type Error = never;fn try_from(value: U) -> Result<T, never>
impl<T, U> TryInto<U> for Literal
where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error;fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>