Module memchr
Fast byte search primitives with SIMD acceleration.
memchr provides optimized routines for searching bytes in slices,
using SIMD acceleration on supported architectures.
It is significantly faster than naive byte-by-byte searching,
often by an order of magnitude for larger inputs.
The primary functions are memchr for finding a single byte,
memchr2 and memchr3 for finding one of 2-3 bytes,
and the memmem module for substring search.
This crate is a foundational building block used by
higher-level crates like regex.
Examples
Finding a single byte:
use memchr;
let haystack = b"hello world";
let needle = b'o';
assert_eq!;
Finding any of multiple bytes:
use memchr2;
let haystack = b"hello world";
// Find the first 'l' or 'w'
assert_eq!;
Substring search with the memmem module:
use memmem;
let haystack = b"the quick brown fox";
let needle = b"quick";
let finder = new;
assert_eq!;
Finding all occurrences:
use memchr_iter;
let haystack = b"hello";
let positions: = memchr_iter.collect;
assert_eq!;