Trait StringZilla
pub trait StringZilla<'a, N>{
Show 16 methods
// Required methods
fn sz_find(&self, needle: N) -> Option<usize> ⓘ;
fn sz_rfind(&self, needle: N) -> Option<usize> ⓘ;
fn sz_find_char_from(&self, needles: N) -> Option<usize> ⓘ;
fn sz_rfind_char_from(&self, needles: N) -> Option<usize> ⓘ;
fn sz_find_char_not_from(&self, needles: N) -> Option<usize> ⓘ;
fn sz_rfind_char_not_from(&self, needles: N) -> Option<usize> ⓘ;
fn sz_edit_distance(&self, other: N) -> usize ⓘ;
fn sz_alignment_score(
&self,
other: N,
matrix: [[i8; 256]; 256],
gap: i8,
) -> isize ⓘ;
fn sz_matches(&'a self, needle: &'a N) -> RangeMatches<'a> ⓘ;
fn sz_rmatches(&'a self, needle: &'a N) -> RangeRMatches<'a> ⓘ;
fn sz_splits(&'a self, needle: &'a N) -> RangeSplits<'a> ⓘ;
fn sz_rsplits(&'a self, needle: &'a N) -> RangeRSplits<'a> ⓘ;
fn sz_find_first_of(&'a self, needles: &'a N) -> RangeMatches<'a> ⓘ;
fn sz_find_last_of(&'a self, needles: &'a N) -> RangeRMatches<'a> ⓘ;
fn sz_find_first_not_of(&'a self, needles: &'a N) -> RangeMatches<'a> ⓘ;
fn sz_find_last_not_of(&'a self, needles: &'a N) -> RangeRMatches<'a> ⓘ;
}
dep_stringzilla
only.Expand description
Provides extensions for string searching and manipulation functionalities
on types that can reference byte slices (u8). This trait extends the capability
of any type implementing AsRef<[u8]>
, allowing easy integration of SIMD-accelerated
string processing functions.
§Examples
Basic usage on a Vec<u8>
:
use stringzilla::StringZilla;
let haystack: &[u8] = &[b'a', b'b', b'c', b'd', b'e'];
let needle: &[u8] = &[b'c', b'd'];
assert_eq!(haystack.sz_find(needle.as_ref()), Some(2));
Searching in a string slice:
use stringzilla::StringZilla;
let haystack = "abcdef";
let needle = "cd";
assert_eq!(haystack.sz_find(needle.as_bytes()), Some(2));
Required Methods§
fn sz_find(&self, needle: N) -> Option<usize> ⓘ
fn sz_find(&self, needle: N) -> Option<usize> ⓘ
Searches for the first occurrence of needle
in self
.
§Examples
use stringzilla::StringZilla;
let haystack = "Hello, world!";
assert_eq!(haystack.sz_find("world".as_bytes()), Some(7));
fn sz_rfind(&self, needle: N) -> Option<usize> ⓘ
fn sz_rfind(&self, needle: N) -> Option<usize> ⓘ
Searches for the last occurrence of needle
in self
.
§Examples
use stringzilla::StringZilla;
let haystack = "Hello, world, world!";
assert_eq!(haystack.sz_rfind("world".as_bytes()), Some(14));
fn sz_find_char_from(&self, needles: N) -> Option<usize> ⓘ
fn sz_find_char_from(&self, needles: N) -> Option<usize> ⓘ
Finds the index of the first character in self
that is also present in needles
.
§Examples
use stringzilla::StringZilla;
let haystack = "Hello, world!";
assert_eq!(haystack.sz_find_char_from("aeiou".as_bytes()), Some(1));
fn sz_rfind_char_from(&self, needles: N) -> Option<usize> ⓘ
fn sz_rfind_char_from(&self, needles: N) -> Option<usize> ⓘ
Finds the index of the last character in self
that is also present in needles
.
§Examples
use stringzilla::StringZilla;
let haystack = "Hello, world!";
assert_eq!(haystack.sz_rfind_char_from("aeiou".as_bytes()), Some(8));
fn sz_find_char_not_from(&self, needles: N) -> Option<usize> ⓘ
fn sz_find_char_not_from(&self, needles: N) -> Option<usize> ⓘ
Finds the index of the first character in self
that is not present in needles
.
§Examples
use stringzilla::StringZilla;
let haystack = "Hello, world!";
assert_eq!(haystack.sz_find_char_not_from("aeiou".as_bytes()), Some(0));
fn sz_rfind_char_not_from(&self, needles: N) -> Option<usize> ⓘ
fn sz_rfind_char_not_from(&self, needles: N) -> Option<usize> ⓘ
Finds the index of the last character in self
that is not present in needles
.
§Examples
use stringzilla::StringZilla;
let haystack = "Hello, world!";
assert_eq!(haystack.sz_rfind_char_not_from("aeiou".as_bytes()), Some(12));
fn sz_edit_distance(&self, other: N) -> usize ⓘ
fn sz_edit_distance(&self, other: N) -> usize ⓘ
Computes the Levenshtein edit distance between self
and other
.
§Examples
use stringzilla::StringZilla;
let first = "kitten";
let second = "sitting";
assert_eq!(first.sz_edit_distance(second.as_bytes()), 3);
fn sz_alignment_score(
&self,
other: N,
matrix: [[i8; 256]; 256],
gap: i8,
) -> isize ⓘ
fn sz_alignment_score( &self, other: N, matrix: [[i8; 256]; 256], gap: i8, ) -> isize ⓘ
Computes the alignment score between self
and other
using the specified
substitution matrix and gap penalty.
§Examples
use stringzilla::{sz, StringZilla};
let first = "kitten";
let second = "sitting";
let matrix = sz::unary_substitution_costs();
let gap_penalty = -1;
assert_eq!(first.sz_alignment_score(second.as_bytes(), matrix, gap_penalty), -3);
fn sz_matches(&'a self, needle: &'a N) -> RangeMatches<'a> ⓘ
fn sz_matches(&'a self, needle: &'a N) -> RangeMatches<'a> ⓘ
Returns an iterator over all non-overlapping matches of the given needle
in self
.
§Arguments
needle
: The byte slice to search for withinself
.
§Examples
use stringzilla::StringZilla;
let haystack = b"abababa";
let needle = b"aba";
let matches: Vec<&[u8]> = haystack.sz_matches(needle).collect();
assert_eq!(matches, vec![b"aba", b"aba", b"aba"]);
fn sz_rmatches(&'a self, needle: &'a N) -> RangeRMatches<'a> ⓘ
fn sz_rmatches(&'a self, needle: &'a N) -> RangeRMatches<'a> ⓘ
Returns an iterator over all non-overlapping matches of the given needle
in self
, searching from the end.
§Arguments
needle
: The byte slice to search for withinself
.
§Examples
use stringzilla::StringZilla;
let haystack = b"abababa";
let needle = b"aba";
let matches: Vec<&[u8]> = haystack.sz_rmatches(needle).collect();
assert_eq!(matches, vec![b"aba", b"aba", b"aba"]);
fn sz_splits(&'a self, needle: &'a N) -> RangeSplits<'a> ⓘ
fn sz_splits(&'a self, needle: &'a N) -> RangeSplits<'a> ⓘ
Returns an iterator over the substrings of self
that are separated by the given needle
.
§Arguments
needle
: The byte slice to splitself
by.
§Examples
use stringzilla::StringZilla;
let haystack = b"a,b,c,d";
let needle = b",";
let splits: Vec<&[u8]> = haystack.sz_splits(needle).collect();
assert_eq!(splits, vec![b"a", b"b", b"c", b"d"]);
fn sz_rsplits(&'a self, needle: &'a N) -> RangeRSplits<'a> ⓘ
fn sz_rsplits(&'a self, needle: &'a N) -> RangeRSplits<'a> ⓘ
Returns an iterator over the substrings of self
that are separated by the given needle
, searching from the end.
§Arguments
needle
: The byte slice to splitself
by.
§Examples
use stringzilla::StringZilla;
let haystack = b"a,b,c,d";
let needle = b",";
let splits: Vec<&[u8]> = haystack.sz_rsplits(needle).collect();
assert_eq!(splits, vec![b"d", b"c", b"b", b"a"]);
fn sz_find_first_of(&'a self, needles: &'a N) -> RangeMatches<'a> ⓘ
fn sz_find_first_of(&'a self, needles: &'a N) -> RangeMatches<'a> ⓘ
Returns an iterator over all non-overlapping matches of any of the bytes in needles
within self
.
§Arguments
needles
: The set of bytes to search for withinself
.
§Examples
use stringzilla::StringZilla;
let haystack = b"Hello, world!";
let needles = b"aeiou";
let matches: Vec<&[u8]> = haystack.sz_find_first_of(needles).collect();
assert_eq!(matches, vec![b"e", b"o", b"o"]);
fn sz_find_last_of(&'a self, needles: &'a N) -> RangeRMatches<'a> ⓘ
fn sz_find_last_of(&'a self, needles: &'a N) -> RangeRMatches<'a> ⓘ
Returns an iterator over all non-overlapping matches of any of the bytes in needles
within self
, searching from the end.
§Arguments
needles
: The set of bytes to search for withinself
.
§Examples
use stringzilla::StringZilla;
let haystack = b"Hello, world!";
let needles = b"aeiou";
let matches: Vec<&[u8]> = haystack.sz_find_last_of(needles).collect();
assert_eq!(matches, vec![b"o", b"o", b"e"]);
fn sz_find_first_not_of(&'a self, needles: &'a N) -> RangeMatches<'a> ⓘ
fn sz_find_first_not_of(&'a self, needles: &'a N) -> RangeMatches<'a> ⓘ
Returns an iterator over all non-overlapping matches of any byte not in needles
within self
.
§Arguments
needles
: The set of bytes that should not be matched withinself
.
§Examples
use stringzilla::StringZilla;
let haystack = b"Hello, world!";
let needles = b"aeiou";
let matches: Vec<&[u8]> = haystack.sz_find_first_not_of(needles).collect();
assert_eq!(matches, vec![b"H", b"l", b"l", b",", b" ", b"w", b"r", b"l", b"d", b"!"]);
fn sz_find_last_not_of(&'a self, needles: &'a N) -> RangeRMatches<'a> ⓘ
fn sz_find_last_not_of(&'a self, needles: &'a N) -> RangeRMatches<'a> ⓘ
Returns an iterator over all non-overlapping matches of any byte not in needles
within self
, searching from the end.
§Arguments
needles
: The set of bytes that should not be matched withinself
. q
§Examples
use stringzilla::StringZilla;
let haystack = b"Hello, world!";
let needles = b"aeiou";
let matches: Vec<&[u8]> = haystack.sz_find_last_not_of(needles).collect();
assert_eq!(matches, vec![b"!", b"d", b"l", b"r", b"w", b" ", b",", b"l", b"l", b"H"]);