Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
marvin-j97 committed Sep 5, 2024
1 parent 50e1cb3 commit 8adf1fc
Showing 2 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 deletions src/byteview.rs
Original file line number Diff line number Diff line change
@@ -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());
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -42,7 +42,8 @@
clippy::pedantic,
clippy::nursery,
clippy::expect_used,
clippy::unwrap_used
clippy::unwrap_used,
clippy::indexing_slicing
)]

mod byteview;

0 comments on commit 8adf1fc

Please sign in to comment.