Skip to content

Commit

Permalink
clippy: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
phip1611 committed May 3, 2024
1 parent 0c13ef8 commit 7b207c1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 34 deletions.
7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ provided by the bootloader.
use tar_no_std::TarArchiveRef;

fn main() {
// log: not mandatory
// init a logger (optional)
std::env::set_var("RUST_LOG", "trace");
env_logger::init();

Expand All @@ -44,11 +44,6 @@ fn main() {
// Vec needs an allocator of course, but the library itself doesn't need one
let entries = archive.entries().collect::<Vec<_>>();
println!("{:#?}", entries);
println!("content of first file:");
println!(
"{:#?}",
entries[0].data_as_str().expect("Should be valid UTF-8")
);
}
```

Expand Down
12 changes: 5 additions & 7 deletions src/archive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,16 +309,14 @@ impl<'a> Iterator for ArchiveEntryIterator<'a> {

// POXIS_1003 long filename check
// https://docs.scinet.utoronto.ca/index.php/(POSIX_1003.1_USTAR)
match (
if (
hdr.magic.as_str(),
hdr.version.as_str(),
hdr.prefix.is_empty(),
) {
(Ok("ustar"), Ok("00"), false) => {
filename.append(&hdr.prefix);
filename.append(&TarFormatString::<1>::new([b'/']));
}
_ => (),
) == (Ok("ustar"), Ok("00"), false)
{
filename.append(&hdr.prefix);
filename.append(&TarFormatString::<1>::new([b'/']));
}
filename.append(&hdr.name);
Some(ArchiveEntry::new(filename, file_bytes))
Expand Down
27 changes: 10 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,23 +60,16 @@ SOFTWARE.
//! ```rust
//! use tar_no_std::TarArchiveRef;
//!
//! fn main() {
//! // log: not mandatory
//! std::env::set_var("RUST_LOG", "trace");
//! env_logger::init();
//!
//! // also works in no_std environment (except the println!, of course)
//! let archive = include_bytes!("../tests/gnu_tar_default.tar");
//! let archive = TarArchiveRef::new(archive).unwrap();
//! // Vec needs an allocator of course, but the library itself doesn't need one
//! let entries = archive.entries().collect::<Vec<_>>();
//! println!("{:#?}", entries);
//! println!("content of first file:");
//! println!(
//! "{:#?}",
//! entries[0].data_as_str().expect("Should be valid UTF-8")
//! );
//! }
//! // init a logger (optional)
//! std::env::set_var("RUST_LOG", "trace");
//! env_logger::init();
//!
//! // also works in no_std environment (except the println!, of course)
//! let archive = include_bytes!("../tests/gnu_tar_default.tar");
//! let archive = TarArchiveRef::new(archive).unwrap();
//! // Vec needs an allocator of course, but the library itself doesn't need one
//! let entries = archive.entries().collect::<Vec<_>>();
//! println!("{:#?}", entries);
//! ```
//!
//! ## Cargo Feature
Expand Down
8 changes: 4 additions & 4 deletions src/tar_format_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ pub struct TarFormatDecimal<const N: usize>(TarFormatNumber<N, 10>);

impl<const N: usize, const R: u32> TarFormatNumber<N, R> {
#[cfg(test)]
fn new(bytes: [u8; N]) -> Self {
const fn new(bytes: [u8; N]) -> Self {
Self(TarFormatString::<N> { bytes })
}

Expand All @@ -121,7 +121,7 @@ impl<const N: usize, const R: u32> TarFormatNumber<N, R> {
}

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

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

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

0 comments on commit 7b207c1

Please sign in to comment.