pub struct FinderRev(/* private fields */);
Expand description
A reverse substring searcher using the Rabin-Karp algorithm.
Implementations§
Source§impl FinderRev
impl FinderRev
Sourcepub fn new(needle: &[u8]) -> FinderRev
pub fn new(needle: &[u8]) -> FinderRev
Create a new Rabin-Karp reverse searcher for the given needle
.
Sourcepub fn rfind(&self, haystack: &[u8], needle: &[u8]) -> Option<usize>
pub fn rfind(&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
.
Sourcepub unsafe fn rfind_raw(
&self,
hstart: *const u8,
hend: *const u8,
nstart: *const u8,
nend: *const u8,
) -> Option<*const u8>
pub unsafe fn rfind_raw( &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
andend
must be valid for reads. - Both
start
andend
must point to an initialized value. - Both
start
andend
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
andend
must be derived from a pointer to the same object. - The distance between
start
andend
must not overflowisize
. - The distance being in bounds must not rely on “wrapping around” the address space.
- It must be the case that
start <= end
.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for FinderRev
impl RefUnwindSafe for FinderRev
impl Send for FinderRev
impl Sync for FinderRev
impl Unpin for FinderRev
impl UnwindSafe for FinderRev
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: 8 bytes