pub struct One(/* private fields */);Expand description
Finds all occurrences of a single byte in a haystack.
Implementations§
source§impl One
impl One
sourcepub fn new(needle: u8) -> Option<One>
pub fn new(needle: u8) -> Option<One>
Create a new searcher that finds occurrences of the needle byte given.
This particular searcher is specialized to use simd128 vector instructions that typically make it quite fast.
If simd128 is unavailable in the current environment, then None is
returned.
sourcepub unsafe fn new_unchecked(needle: u8) -> One
Available with target feature simd128 only.
pub unsafe fn new_unchecked(needle: u8) -> One
simd128 only.Create a new finder specific to simd128 vectors and routines without checking that simd128 is available.
Safety
Callers must guarantee that it is safe to execute simd128
instructions in the current environment.
sourcepub 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 One::new will return
a Some value. Similarly, when it is false, it is guaranteed that
One::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.
sourcepub 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.
sourcepub 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.
sourcepub fn count(&self, haystack: &[u8]) -> usize
pub fn count(&self, haystack: &[u8]) -> usize
Counts all occurrences of this byte in the given haystack.
sourcepub 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.
sourcepub 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.
sourcepub unsafe fn count_raw(&self, start: *const u8, end: *const u8) -> usize
pub unsafe fn count_raw(&self, start: *const u8, end: *const u8) -> usize
Counts all occurrences of this byte in the given haystack represented by 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.