Skip to content

Commit

Permalink
Merge pull request #21 from phip1611/clippy
Browse files Browse the repository at this point in the history
clippy: add clippy::must_use_candidat
  • Loading branch information
phip1611 authored Jul 10, 2024
2 parents d81f539 + f7521e5 commit 7ef31a2
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,13 @@ impl<'a> ArchiveEntry<'a> {

/// Filename of the entry with a maximum of 100 characters (including the
/// terminating NULL-byte).
#[must_use]
pub const fn filename(&self) -> TarFormatString<{ POSIX_1003_MAX_FILENAME_LEN }> {
self.filename
}

/// Data of the file.
#[must_use]
pub const fn data(&self) -> &'a [u8] {
self.data
}
Expand All @@ -74,6 +76,7 @@ impl<'a> ArchiveEntry<'a> {
}

/// Filesize in bytes.
#[must_use]
pub const fn size(&self) -> usize {
self.size
}
Expand Down Expand Up @@ -174,6 +177,7 @@ impl<'a> TarArchiveRef<'a> {
}

/// Creates an [`ArchiveEntryIterator`].
#[must_use]
pub fn entries(&self) -> ArchiveEntryIterator {
ArchiveEntryIterator::new(self.data)
}
Expand All @@ -187,6 +191,7 @@ pub struct ArchiveHeaderIterator<'a> {
}

impl<'a> ArchiveHeaderIterator<'a> {
#[must_use]
pub fn new(archive: &'a [u8]) -> Self {
assert!(!archive.is_empty());
assert_eq!(archive.len() % BLOCKSIZE, 0);
Expand Down
2 changes: 2 additions & 0 deletions src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ pub enum TypeFlag {

impl TypeFlag {
/// Whether we have a regular file.
#[must_use]
pub fn is_regular_file(self) -> bool {
// Equivalent. See spec.
self == Self::AREGTYPE || self == Self::REGTYPE
Expand Down Expand Up @@ -257,6 +258,7 @@ impl PosixHeader {

/// A Tar archive is terminated, if an end-of-archive entry, which consists
/// of two 512 blocks of zero bytes, is found.
#[must_use]
pub fn is_zero_block(&self) -> bool {
let ptr = self as *const Self as *const u8;
let self_bytes = unsafe { core::slice::from_raw_parts(ptr, BLOCKSIZE) };
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ SOFTWARE.
clippy::all,
clippy::cargo,
clippy::nursery,
clippy::must_use_candidate,
// clippy::restriction,
// clippy::pedantic
)]
Expand Down
6 changes: 6 additions & 0 deletions src/tar_format_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ pub struct TarFormatString<const N: usize> {
/// This string will be null terminated if it doesn't fill the entire array.
impl<const N: usize> TarFormatString<N> {
/// Constructor.
#[must_use]
pub const fn new(bytes: [u8; N]) -> Self {
if N == 0 {
panic!("Array cannot be zero length");
Expand All @@ -31,12 +32,14 @@ impl<const N: usize> TarFormatString<N> {
}

/// True if the is string empty (ignoring NULL bytes).
#[must_use]
pub const fn is_empty(&self) -> bool {
self.bytes[0] == 0
}

/// Returns the length of the payload in bytes. This is either the full
/// capacity `N` or the data until the first NULL byte.
#[must_use]
pub fn size(&self) -> usize {
memchr::memchr(0, &self.bytes).unwrap_or(N)
}
Expand Down Expand Up @@ -121,6 +124,7 @@ impl<const N: usize, const R: u32> TarFormatNumber<N, R> {
}

/// Returns the underlying [`TarFormatString`].
#[must_use]
pub const fn as_inner(&self) -> &TarFormatString<N> {
&self.0
}
Expand Down Expand Up @@ -157,6 +161,7 @@ impl<const N: usize> TarFormatDecimal<N> {
}

/// Returns the underlying [`TarFormatString`].
#[must_use]
pub const fn as_inner(&self) -> &TarFormatString<N> {
self.0.as_inner()
}
Expand All @@ -171,6 +176,7 @@ impl<const N: usize> TarFormatOctal<N> {
}

/// Returns the underlying [`TarFormatString`].
#[must_use]
pub const fn as_inner(&self) -> &TarFormatString<N> {
self.0.as_inner()
}
Expand Down

0 comments on commit 7ef31a2

Please sign in to comment.