From 8adf1fc7c9a4ad0ee08f7784ec039e847be8d591 Mon Sep 17 00:00:00 2001 From: marvin-j97 Date: Thu, 5 Sep 2024 16:40:54 +0200 Subject: [PATCH] refactor --- src/byteview.rs | 17 +++++++++++------ src/lib.rs | 3 ++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/byteview.rs b/src/byteview.rs index 98be33b..f689946 100644 --- a/src/byteview.rs +++ b/src/byteview.rs @@ -170,7 +170,8 @@ impl ByteView { /// # Panics /// /// Panics if the length does not fit in a u32 (4 GiB). - #[must_use] pub fn new(slice: &[u8]) -> Self { + #[must_use] + pub fn new(slice: &[u8]) -> Self { let slice_len = slice.len(); let Ok(len) = u32::try_from(slice_len) else { @@ -252,7 +253,8 @@ impl ByteView { /// Returns the ref_count of the underlying heap allocation. #[doc(hidden)] - #[must_use] pub fn ref_count(&self) -> u64 { + #[must_use] + pub fn ref_count(&self) -> u64 { if self.is_inline() { 1 } else { @@ -261,7 +263,8 @@ impl ByteView { } /// Clones the contents of this slice into an independently tracked slice. - #[must_use] pub fn to_detached(&self) -> Self { + #[must_use] + pub fn to_detached(&self) -> Self { Self::new(self) } @@ -391,12 +394,14 @@ impl ByteView { } /// Returns `true` if the slice is empty. - #[must_use] pub const fn is_empty(&self) -> bool { + #[must_use] + pub const fn is_empty(&self) -> bool { self.len == 0 } /// Returns the amount of bytes in the slice. - #[must_use] pub const fn len(&self) -> usize { + #[must_use] + pub const fn len(&self) -> usize { self.len as usize } @@ -706,7 +711,7 @@ mod tests { { let copycopy = copy.slice(0..=4); assert_eq!(b"thisi", &*copycopy); - assert_eq!(b't', copycopy[0]); + assert_eq!(b't', *copycopy.first().unwrap()); } assert_eq!(1, slice.ref_count()); diff --git a/src/lib.rs b/src/lib.rs index 072ec9a..dc33220 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -42,7 +42,8 @@ clippy::pedantic, clippy::nursery, clippy::expect_used, - clippy::unwrap_used + clippy::unwrap_used, + clippy::indexing_slicing )] mod byteview;