Skip to content

Commit

Permalink
feat(stream): Allow finding chars in byte slices
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Feb 12, 2024
1 parent e38ab2b commit 0d28d90
Showing 1 changed file with 47 additions and 18 deletions.
65 changes: 47 additions & 18 deletions src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2489,6 +2489,48 @@ impl<'i, 's> FindSlice<(&'s [u8], &'s [u8], &'s [u8])> for &'i [u8] {
}
}

impl<'i> FindSlice<char> for &'i [u8] {
#[inline(always)]
fn find_slice(&self, substr: char) -> Option<crate::lib::std::ops::Range<usize>> {
let mut b = [0; 4];
let substr = substr.encode_utf8(&mut b);
self.find_slice(&*substr)
}
}

impl<'i> FindSlice<(char,)> for &'i [u8] {
#[inline(always)]
fn find_slice(&self, substr: (char,)) -> Option<crate::lib::std::ops::Range<usize>> {
let mut b = [0; 4];
let substr0 = substr.0.encode_utf8(&mut b);
self.find_slice((&*substr0,))
}
}

impl<'i> FindSlice<(char, char)> for &'i [u8] {
#[inline(always)]
fn find_slice(&self, substr: (char, char)) -> Option<crate::lib::std::ops::Range<usize>> {
let mut b = [0; 4];
let substr0 = substr.0.encode_utf8(&mut b);
let mut b = [0; 4];
let substr1 = substr.1.encode_utf8(&mut b);
self.find_slice((&*substr0, &*substr1))
}
}

impl<'i> FindSlice<(char, char, char)> for &'i [u8] {
#[inline(always)]
fn find_slice(&self, substr: (char, char, char)) -> Option<crate::lib::std::ops::Range<usize>> {
let mut b = [0; 4];
let substr0 = substr.0.encode_utf8(&mut b);
let mut b = [0; 4];
let substr1 = substr.1.encode_utf8(&mut b);
let mut b = [0; 4];
let substr2 = substr.2.encode_utf8(&mut b);
self.find_slice((&*substr0, &*substr1, &*substr2))
}
}

impl<'i> FindSlice<u8> for &'i [u8] {
#[inline(always)]
fn find_slice(&self, substr: u8) -> Option<usize> {
Expand Down Expand Up @@ -2583,42 +2625,29 @@ impl<'i, 's> FindSlice<(&'s str, &'s str, &'s str)> for &'i str {
impl<'i> FindSlice<char> for &'i str {
#[inline(always)]
fn find_slice(&self, substr: char) -> Option<usize> {
let mut b = [0; 4];
let substr = substr.encode_utf8(&mut b);
self.find_slice(&*substr)
self.as_bytes().find_slice(substr)
}
}

impl<'i> FindSlice<(char,)> for &'i str {
#[inline(always)]
fn find_slice(&self, substr: (char,)) -> Option<usize> {
let mut b = [0; 4];
let substr0 = substr.0.encode_utf8(&mut b);
self.find_slice((&*substr0,))
self.as_bytes().find_slice(substr)
}
}

impl<'i> FindSlice<(char, char)> for &'i str {
#[inline(always)]
fn find_slice(&self, substr: (char, char)) -> Option<usize> {
let mut b = [0; 4];
let substr0 = substr.0.encode_utf8(&mut b);
let mut b = [0; 4];
let substr1 = substr.1.encode_utf8(&mut b);
self.find_slice((&*substr0, &*substr1))
fn find_slice(&self, substr: (char, char)) -> Option<crate::lib::std::ops::Range<usize>> {

Check failure

Code scanning / clippy

self parameter is only allowed in associated functions Error

self parameter is only allowed in associated functions

Check failure

Code scanning / clippy

can't use generic parameters from outer function Error

can't use generic parameters from outer function

Check failure

Code scanning / clippy

can't use generic parameters from outer function Error

can't use generic parameters from outer function

Check failure

Code scanning / clippy

self parameter is only allowed in associated functions Error

self parameter is only allowed in associated functions

Check failure

Code scanning / clippy

can't use generic parameters from outer function Error

can't use generic parameters from outer function

Check failure

Code scanning / clippy

can't use generic parameters from outer function Error

can't use generic parameters from outer function
self.as_bytes().find_slice(substr)
}
}

impl<'i> FindSlice<(char, char, char)> for &'i str {
#[inline(always)]
fn find_slice(&self, substr: (char, char, char)) -> Option<usize> {
let mut b = [0; 4];
let substr0 = substr.0.encode_utf8(&mut b);
let mut b = [0; 4];
let substr1 = substr.1.encode_utf8(&mut b);
let mut b = [0; 4];
let substr2 = substr.2.encode_utf8(&mut b);
self.find_slice((&*substr0, &*substr1, &*substr2))
self.as_bytes().find_slice(substr)
}
}

Expand Down

0 comments on commit 0d28d90

Please sign in to comment.