Skip to content

Commit abd1e6e

Browse files
committed
Move NeedleWithSize trait to lib.rs
1 parent 2ae45c2 commit abd1e6e

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,24 @@ impl Needle for Vec<u8> {
106106
}
107107
}
108108

109+
trait NeedleWithSize: Needle {
110+
#[inline]
111+
fn size(&self) -> usize {
112+
if let Some(size) = Self::SIZE {
113+
size
114+
} else {
115+
self.as_bytes().len()
116+
}
117+
}
118+
119+
#[inline]
120+
fn is_empty(&self) -> bool {
121+
self.size() == 0
122+
}
123+
}
124+
125+
impl<N: Needle + ?Sized> NeedleWithSize for N {}
126+
109127
/// Single-byte searcher using `memchr` for faster matching.
110128
pub struct MemchrSearcher(u8);
111129

src/x86.rs

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,12 @@
11
#![allow(clippy::missing_safety_doc)]
22

3-
use crate::{bits, memcmp, MemchrSearcher, Needle};
3+
use crate::{bits, memcmp, MemchrSearcher, Needle, NeedleWithSize};
44
use seq_macro::seq;
55
#[cfg(target_arch = "x86")]
66
use std::arch::x86::*;
77
#[cfg(target_arch = "x86_64")]
88
use std::arch::x86_64::*;
99

10-
trait NeedleWithSize: Needle {
11-
#[inline]
12-
fn size(&self) -> usize {
13-
if let Some(size) = Self::SIZE {
14-
size
15-
} else {
16-
self.as_bytes().len()
17-
}
18-
}
19-
20-
#[inline]
21-
fn is_empty(&self) -> bool {
22-
self.size() == 0
23-
}
24-
}
25-
26-
impl<N: Needle + ?Sized> NeedleWithSize for N {}
27-
2810
/// Represents an SIMD register type that is x86-specific (but could be used
2911
/// more generically) in order to share functionality between SSE2, AVX2 and
3012
/// possibly future implementations.

0 commit comments

Comments
 (0)