Struct Three
pub struct Three(/* private fields */);dep_memchr only.Expand description
Finds all occurrences of three bytes in a haystack.
That is, this reports matches of one of three possible bytes. For example,
searching for a, b or o in afoobar would report matches at offsets
0, 2, 3, 4 and 5.
Implementations§
§impl Three
impl Three
pub fn new(needle1: u8, needle2: u8, needle3: u8) -> Option<Three> ⓘ
pub fn new(needle1: u8, needle2: u8, needle3: u8) -> Option<Three> ⓘ
Create a new searcher that finds occurrences of the needle bytes given.
This particular searcher is specialized to use SSE2 vector instructions that typically make it quite fast.
If SSE2 is unavailable in the current environment, then None is
returned.
pub unsafe fn new_unchecked(needle1: u8, needle2: u8, needle3: u8) -> Three
pub unsafe fn new_unchecked(needle1: u8, needle2: u8, needle3: u8) -> Three
Create a new finder specific to SSE2 vectors and routines without checking that SSE2 is available.
§Safety
Callers must guarantee that it is safe to execute sse2 instructions
in the current environment.
Note that it is a common misconception that if one compiles for an
x86_64 target, then they therefore automatically have access to SSE2
instructions. While this is almost always the case, it isn’t true in
100% of cases.
pub fn is_available() -> bool
pub fn is_available() -> bool
Returns true when this implementation is available in the current environment.
When this is true, it is guaranteed that Three::new will return
a Some value. Similarly, when it is false, it is guaranteed that
Three::new will return a None value.
Note also that for the lifetime of a single program, if this returns true then it will always return true.
pub fn find(&self, haystack: &[u8]) -> Option<usize> ⓘ
pub fn find(&self, haystack: &[u8]) -> Option<usize> ⓘ
Return the first occurrence of one of the needle bytes in the given
haystack. If no such occurrence exists, then None is returned.
The occurrence is reported as an offset into haystack. Its maximum
value is haystack.len() - 1.
pub fn rfind(&self, haystack: &[u8]) -> Option<usize> ⓘ
pub fn rfind(&self, haystack: &[u8]) -> Option<usize> ⓘ
Return the last occurrence of one of the needle bytes in the given
haystack. If no such occurrence exists, then None is returned.
The occurrence is reported as an offset into haystack. Its maximum
value is haystack.len() - 1.
pub unsafe fn find_raw(
&self,
start: *const u8,
end: *const u8,
) -> Option<*const u8> ⓘ
pub unsafe fn find_raw( &self, start: *const u8, end: *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
>= start and < end.
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
- 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.
Note that callers may pass a pair of pointers such that start >= end.
In that case, None will always be returned.
pub unsafe fn rfind_raw(
&self,
start: *const u8,
end: *const u8,
) -> Option<*const u8> ⓘ
pub unsafe fn rfind_raw( &self, start: *const u8, end: *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.
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
- 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.
Note that callers may pass a pair of pointers such that start >= end.
In that case, None will always be returned.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Three
impl RefUnwindSafe for Three
impl Send for Three
impl Sync for Three
impl Unpin for Three
impl UnwindSafe for Three
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> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId of Self using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout only.T represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more