Struct FinderRev

struct FinderRev(_)

A reverse substring searcher using the Rabin-Karp algorithm.

Implementations

impl FinderRev

fn new(needle: &[u8]) -> FinderRev

Create a new Rabin-Karp reverse searcher for the given needle.

fn rfind(self: &Self, haystack: &[u8], needle: &[u8]) -> Option<usize>

Return the last occurrence of the needle in the haystack given. If no such occurrence exists, then None is returned.

The needle provided must match the needle given to this finder at construction time.

The maximum value this can return is haystack.len(), which can only occur when the needle and haystack both have length zero. Otherwise, for non-empty haystacks, the maximum value is haystack.len() - 1.

unsafe fn rfind_raw(self: &Self, hstart: *const u8, hend: *const u8, nstart: *const u8, nend: *const u8) -> Option<*const u8>

Like rfind, but accepts and returns raw pointers.

When a match is found, the pointer returned is guaranteed to be >= start and <= end. The pointer returned is only ever equivalent to end when both the needle and haystack are empty. (That is, the empty string matches the empty string.)

This routine is useful if you're already using raw pointers and would like to avoid converting back to a slice before executing a search.

Safety

Note that start and end below refer to both pairs of pointers given to this routine. That is, the conditions apply to both hstart/hend and nstart/nend.

  • Both start and end must be valid for reads.
  • Both start and end must point to an initialized value.
  • Both start and end must point to the same allocated object and must either be in bounds or at most one byte past the end of the allocated object.
  • Both start and end must be derived from a pointer to the same object.
  • The distance between start and end must not overflow isize.
  • The distance being in bounds must not rely on "wrapping around" the address space.
  • It must be the case that start <= end.

impl Clone for FinderRev

fn clone(self: &Self) -> FinderRev

impl Debug for FinderRev

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

impl Freeze for FinderRev

impl RefUnwindSafe for FinderRev

impl Send for FinderRev

impl Sync for FinderRev

impl Unpin for FinderRev

impl UnwindSafe for FinderRev

impl<T> Any for FinderRev

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for FinderRev

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for FinderRev

fn borrow_mut(self: &mut Self) -> &mut T

impl<T> CloneToUninit for FinderRev

unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)

impl<T> From for FinderRev

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for FinderRev

fn to_owned(self: &Self) -> T
fn clone_into(self: &Self, target: &mut T)

impl<T, U> Into for FinderRev

fn into(self: Self) -> U

Calls U::from(self).

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

impl<T, U> TryFrom for FinderRev

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto for FinderRev

fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>