@@ -248,19 +248,19 @@ impl<'b> PackedCompareControl for &'b Bytes {
248248 }
249249}
250250
251- pub struct ByteSubstring < ' a > {
252- complete_needle : & ' a [ u8 ] ,
251+ pub struct ByteSubstring < T > {
252+ complete_needle : T ,
253253 needle : __m128i ,
254254 needle_len : i32 ,
255255}
256256
257- impl < ' a > ByteSubstring < ' a > {
258- pub /* const */ fn new ( needle : & ' a [ u8 ] ) -> Self {
257+ impl < T > ByteSubstring < T > where T : AsRef < [ u8 ] > {
258+ pub /* const */ fn new ( needle : T ) -> Self {
259259 use std:: cmp;
260260
261261 let mut simd_needle = [ 0 ; 16 ] ;
262262 let len = cmp:: min ( simd_needle. len ( ) , needle. len ( ) ) ;
263- simd_needle[ ..len] . copy_from_slice ( & needle[ ..len] ) ;
263+ simd_needle[ ..len] . copy_from_slice ( & needle. as_ref ( ) [ ..len] ) ;
264264 ByteSubstring {
265265 complete_needle : needle,
266266 needle : unsafe { TransmuteToSimd { bytes : simd_needle } . simd } ,
@@ -270,7 +270,7 @@ impl<'a> ByteSubstring<'a> {
270270
271271 #[ cfg( feature = "pattern" ) ]
272272 pub fn needle_len ( & self ) -> usize {
273- self . complete_needle . len ( )
273+ self . complete_needle . as_ref ( ) . len ( )
274274 }
275275
276276 #[ inline]
@@ -281,7 +281,7 @@ impl<'a> ByteSubstring<'a> {
281281 while let Some ( idx) = find ( PackedCompare :: < _ , _SIDD_CMP_EQUAL_ORDERED > ( self ) , & haystack[ offset..] ) {
282282 let abs_offset = offset + idx;
283283 // Found a match, but is it really?
284- if haystack[ abs_offset..] . starts_with ( self . complete_needle ) {
284+ if haystack[ abs_offset..] . starts_with ( self . complete_needle . as_ref ( ) ) {
285285 return Some ( abs_offset) ;
286286 }
287287
0 commit comments