Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Jan 17, 2022
1 parent 347c955 commit 601787d
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion experimental/tinystr_neo/src/ascii.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ impl<const N: usize> TinyAsciiStr<N> {
self.bytes.iter().position(|x| *x == 0).unwrap_or(N)
}

pub fn is_empty(&self) -> bool {
self.bytes[0] == 0
}

pub fn as_bytes(&self) -> &[u8] {
&self.bytes[0..self.len()]
}
Expand All @@ -61,6 +65,9 @@ impl<const N: usize> TinyAsciiStr<N> {
&self.bytes
}

/// # Safety
/// Must be called with a bytes array made of valid ASCII bytes, with no null bytes
/// between ASCII characters
pub const unsafe fn from_bytes_unchecked(bytes: [u8; N]) -> Self {
Self { bytes }
}
Expand All @@ -69,7 +76,7 @@ impl<const N: usize> TinyAsciiStr<N> {
impl<const N: usize> Deref for TinyAsciiStr<N> {
type Target = str;
fn deref(&self) -> &str {
unsafe { str::from_utf8_unchecked(&self.as_bytes()) }
unsafe { str::from_utf8_unchecked(self.as_bytes()) }
}
}

Expand Down

0 comments on commit 601787d

Please sign in to comment.