Struct FinderRev
struct FinderRev<'n> { ... }
A single substring reverse searcher fixed to a particular needle.
The purpose of this type is to permit callers to construct a substring
searcher that can be used to search haystacks without the overhead of
constructing the searcher in the first place. This is a somewhat niche
concern when it's necessary to re-use the same needle to search multiple
different haystacks with as little overhead as possible. In general,
using rfind is good enough, but FinderRev is useful when you can
meaningfully observe searcher construction time in a profile.
When the std feature is enabled, then this type has an into_owned
version which permits building a FinderRev that is not connected to
the lifetime of its needle.
Implementations
impl<'n> FinderRev<'n>
fn new<B: ?Sized + AsRef<[u8]>>(needle: &'n B) -> FinderRev<'n>Create a new reverse finder for the given needle.
fn rfind<B: AsRef<[u8]>>(self: &Self, haystack: B) -> Option<usize>Returns the index of the last occurrence of this needle in the given haystack.
The haystack may be any type that can be cheaply converted into a
&[u8]. This includes, but is not limited to,&strand&[u8].Complexity
This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in
O(needle.len() + haystack.len())time.This routine is also guaranteed to have worst case constant space complexity.
Examples
Basic usage:
use FinderRev; let haystack = b"foo bar baz"; assert_eq!; assert_eq!; assert_eq!;fn rfind_iter<'a, 'h>(self: &'a Self, haystack: &'h [u8]) -> FindRevIter<'h, 'a>Returns a reverse iterator over all occurrences of a substring in a haystack.
Complexity
This routine is guaranteed to have worst case linear time complexity with respect to both the needle and the haystack. That is, this runs in
O(needle.len() + haystack.len())time.This routine is also guaranteed to have worst case constant space complexity.
Examples
Basic usage:
use FinderRev; let haystack = b"foo bar foo baz foo"; let finder = new; let mut it = finder.rfind_iter; assert_eq!; assert_eq!; assert_eq!; assert_eq!;fn into_owned(self: Self) -> FinderRev<'static>Convert this finder into its owned variant, such that it no longer borrows the needle.
If this is already an owned finder, then this is a no-op. Otherwise, this copies the needle.
This is only available when the
stdfeature is enabled.fn as_ref(self: &Self) -> FinderRev<'_>Convert this finder into its borrowed variant.
This is primarily useful if your finder is owned and you'd like to store its borrowed variant in some intermediate data structure.
Note that the lifetime parameter of the returned finder is tied to the lifetime of
self, and may be shorter than the'nlifetime of the needle itself. Namely, a finder's needle can be either borrowed or owned, so the lifetime of the needle returned must necessarily be the shorter of the two.fn needle(self: &Self) -> &[u8]Returns the needle that this finder searches for.
Note that the lifetime of the needle returned is tied to the lifetime of the finder, and may be shorter than the
'nlifetime. Namely, a finder's needle can be either borrowed or owned, so the lifetime of the needle returned must necessarily be the shorter of the two.
impl<'n> Clone for FinderRev<'n>
fn clone(self: &Self) -> FinderRev<'n>
impl<'n> Debug for FinderRev<'n>
fn fmt(self: &Self, f: &mut $crate::fmt::Formatter<'_>) -> $crate::fmt::Result
impl<'n> Freeze for FinderRev<'n>
impl<'n> RefUnwindSafe for FinderRev<'n>
impl<'n> Send for FinderRev<'n>
impl<'n> Sync for FinderRev<'n>
impl<'n> Unpin for FinderRev<'n>
impl<'n> UnwindSafe for FinderRev<'n>
impl<T> Any for FinderRev<'n>
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for FinderRev<'n>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for FinderRev<'n>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for FinderRev<'n>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for FinderRev<'n>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for FinderRev<'n>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for FinderRev<'n>
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 FinderRev<'n>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for FinderRev<'n>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>