Struct Finder
struct Finder { ... }
A forward substring searcher using the Rabin-Karp algorithm.
Note that, as a lower level API, a Finder does not have access to the
needle it was constructed with. For this reason, executing a search
with a Finder requires passing both the needle and the haystack,
where the needle is exactly equivalent to the one given to the Finder
at construction time. This design was chosen so that callers can have
more precise control over where and how many times a needle is stored.
For example, in cases where Rabin-Karp is just one of several possible
substring search algorithms.
Implementations
impl Finder
fn new(needle: &[u8]) -> FinderCreate a new Rabin-Karp forward searcher for the given
needle.The needle may be empty. The empty needle matches at every byte offset.
Note that callers must pass the same needle to all search calls using this
Finder.fn find(self: &Self, haystack: &[u8], needle: &[u8]) -> Option<usize>Return the first occurrence of the
needlein thehaystackgiven. If no such occurrence exists, thenNoneis returned.The
needleprovided 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 ishaystack.len() - 1.unsafe fn find_raw(self: &Self, hstart: *const u8, hend: *const u8, nstart: *const u8, nend: *const u8) -> Option<*const u8>Like
find, but accepts and returns raw pointers.When a match is found, the pointer returned is guaranteed to be
>= startand<= end. The pointer returned is only ever equivalent toendwhen 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
startandendbelow refer to both pairs of pointers given to this routine. That is, the conditions apply to bothhstart/hendandnstart/nend.- Both
startandendmust be valid for reads. - Both
startandendmust point to an initialized value. - Both
startandendmust 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
startandendmust be derived from a pointer to the same object. - The distance between
startandendmust not overflowisize. - The distance being in bounds must not rely on "wrapping around" the address space.
- It must be the case that
start <= end.
- Both
impl Clone for Finder
fn clone(self: &Self) -> Finder
impl Debug for Finder
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl Freeze for Finder
impl RefUnwindSafe for Finder
impl Send for Finder
impl Sync for Finder
impl Unpin for Finder
impl UnwindSafe for Finder
impl<T> Any for Finder
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Finder
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Finder
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Finder
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Finder
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Finder
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Finder
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Finder
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Finder
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>