Struct memchr::arch::all::memchr::One

source ·
pub struct One { /* private fields */ }
Expand description

Finds all occurrences of a single byte in a haystack.

Implementations§

source§

impl One

source

pub fn new(needle: u8) -> One

Create a new searcher that finds occurrences of the byte given.

source

pub fn find(&self, haystack: &[u8]) -> Option<usize>

Return the first occurrence of the needle 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 for a non-empty haystack is haystack.len() - 1.

source

pub fn rfind(&self, haystack: &[u8]) -> Option<usize>

Return the last occurrence of the needle 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 for a non-empty haystack is haystack.len() - 1.

source

pub fn count(&self, haystack: &[u8]) -> usize

Counts all occurrences of this byte in the given haystack.

source

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 start and end must be valid for reads.
  • Both start and end must point to an initialized value.
  • Both start and end 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 and end must be derived from a pointer to the same object.
  • The distance between start and end must not overflow isize.
  • 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.

source

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 start and end must be valid for reads.
  • Both start and end must point to an initialized value.
  • Both start and end 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 and end must be derived from a pointer to the same object.
  • The distance between start and end must not overflow isize.
  • 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.

source

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.

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 start and end must be valid for reads.
  • Both start and end must point to an initialized value.
  • Both start and end 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 and end must be derived from a pointer to the same object.
  • The distance between start and end must not overflow isize.
  • 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, 0 will always be returned.

source

pub fn iter<'a, 'h>(&'a self, haystack: &'h [u8]) -> OneIter<'a, 'h>

Returns an iterator over all occurrences of the needle byte in the given haystack.

The iterator returned implements DoubleEndedIterator. This means it can also be used to find occurrences in reverse order.

Trait Implementations§

source§

impl Clone for One

source§

fn clone(&self) -> One

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for One

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Copy for One

Auto Trait Implementations§

§

impl RefUnwindSafe for One

§

impl Send for One

§

impl Sync for One

§

impl Unpin for One

§

impl UnwindSafe for One

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.