Skip to content

Commit

Permalink
Apply clippy suggesions
Browse files Browse the repository at this point in the history
Mostly just adding #[must_use]
  • Loading branch information
Dr-Emann committed Oct 13, 2023
1 parent 9aacf0e commit 319143a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/fallback.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where
}

pub fn find(&self, haystack: &[u8]) -> Option<usize> {
haystack.iter().cloned().position(&self.fallback)
haystack.iter().copied().position(&self.fallback)
}
}

Expand Down
12 changes: 12 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ where
/// intrinsics are not available. The closure **must** search for
/// the same bytes as in the array.
#[allow(unused_variables)]
#[must_use]
pub fn new(bytes: [u8; 16], len: i32, fallback: F) -> Self {
Bytes {
#[cfg(any(jetscii_sse4_2 = "yes", jetscii_sse4_2 = "maybe"))]
Expand All @@ -222,6 +223,7 @@ where
// the fallback at all, so it will be dropped in this function.
#[doc(hidden)]
#[allow(unused_variables)]
#[must_use]
pub const fn new_const(bytes: [u8; 16], len: i32, fallback: F) -> Self
where
F: Copy,
Expand All @@ -239,6 +241,7 @@ where

/// Searches the slice for the first matching byte in the set.
#[inline]
#[must_use]
pub fn find(&self, haystack: &[u8]) -> Option<usize> {
dispatch! {
simd: unsafe { self.simd.find(haystack) },
Expand Down Expand Up @@ -268,6 +271,7 @@ where
/// ### Panics
///
/// - If you provide a non-ASCII byte.
#[must_use]
pub fn new(chars: [u8; 16], len: i32, fallback: F) -> Self {
for &b in &chars {
assert!(b < 128, "Cannot have non-ASCII bytes");
Expand All @@ -281,6 +285,7 @@ where
// (thus, have no destructor). If we _know_ we're using sse4.2, we don't use
// the fallback at all, so it will be dropped in this function.
#[doc(hidden)]
#[must_use]
pub const fn new_const(chars: [u8; 16], len: i32, fallback: F) -> Self
where
F: Copy,
Expand All @@ -295,6 +300,7 @@ where

/// Searches the string for the first matching ASCII byte in the set.
#[inline]
#[must_use]
pub fn find(&self, haystack: &str) -> Option<usize> {
self.0.find(haystack.as_bytes())
}
Expand All @@ -313,6 +319,7 @@ pub struct ByteSubstring<'a> {
}

impl<'a> ByteSubstring<'a> {
#[must_use]
pub const fn new(needle: &'a [u8]) -> Self {
ByteSubstring {
#[cfg(any(jetscii_sse4_2 = "yes", jetscii_sse4_2 = "maybe"))]
Expand All @@ -324,6 +331,7 @@ impl<'a> ByteSubstring<'a> {
}

#[cfg(feature = "pattern")]
#[must_use]
fn needle_len(&self) -> usize {
dispatch! {
simd: self.simd.needle_len(),
Expand All @@ -333,6 +341,7 @@ impl<'a> ByteSubstring<'a> {

/// Searches the slice for the first occurence of the subslice.
#[inline]
#[must_use]
pub fn find(&self, haystack: &[u8]) -> Option<usize> {
dispatch! {
simd: unsafe { self.simd.find(haystack) },
Expand All @@ -348,17 +357,20 @@ pub type ByteSubstringConst = ByteSubstring<'static>;
pub struct Substring<'a>(ByteSubstring<'a>);

impl<'a> Substring<'a> {
#[must_use]
pub const fn new(needle: &'a str) -> Self {
Substring(ByteSubstring::new(needle.as_bytes()))
}

#[cfg(feature = "pattern")]
#[must_use]
fn needle_len(&self) -> usize {
self.0.needle_len()
}

/// Searches the string for the first occurence of the substring.
#[inline]
#[must_use]
pub fn find(&self, haystack: &str) -> Option<usize> {
self.0.find(haystack.as_bytes())
}
Expand Down
2 changes: 1 addition & 1 deletion src/simd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ where
packed.cmpestri(haystack.as_ptr(), haystack.len() as i32)
}

/// The PCMPxSTRx instructions always read 16 bytes worth of
/// The `PCMPxSTRx` instructions always read 16 bytes worth of
/// data. Although the instructions handle unaligned memory access
/// just fine, they might attempt to read off the end of a page
/// and into a protected area.
Expand Down

0 comments on commit 319143a

Please sign in to comment.