Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Enforce stricter clippy rules #23

Merged
merged 5 commits into from
Feb 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/entries/bundle_entry.rs
Original file line number Diff line number Diff line change
@@ -5,7 +5,7 @@ use super::chunk_entry::ChunkEntry;
/// Single bundle entry object.
///
/// This is identical to the schema in [rman-schema][rman-schema] and exists to provide a
/// persistent structure for the BundleEntry.
/// persistent structure for the `BundleEntry`.
///
/// [rman-schema]: https://github.com/ev3nvy/rman-schema
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2 changes: 1 addition & 1 deletion src/entries/chunk_entry.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::generated::rman::Chunk;
/// Single chunk entry object.
///
/// This is identical to the schema in [rman-schema][rman-schema] and exists to provide a
/// persistent structure for the ChunkEntry.
/// persistent structure for the `ChunkEntry`.
///
/// [rman-schema]: https://github.com/ev3nvy/rman-schema
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2 changes: 1 addition & 1 deletion src/entries/directory_entry.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::generated::rman::Directory;
/// Single directory entry object.
///
/// This is identical to the schema in [rman-schema][rman-schema] and exists to provide a
/// persistent structure for the DirectoryEntry.
/// persistent structure for the `DirectoryEntry`.
///
/// [rman-schema]: https://github.com/ev3nvy/rman-schema
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2 changes: 1 addition & 1 deletion src/entries/file_entry.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::generated::rman::File;
/// Single file entry object.
///
/// This is identical to the schema in [rman-schema][rman-schema] and exists to provide a
/// persistent structure for the FileEntry.
/// persistent structure for the `FileEntry`.
///
/// [rman-schema]: https://github.com/ev3nvy/rman-schema
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2 changes: 1 addition & 1 deletion src/entries/key_entry.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::generated::rman::Key;
/// Single key entry object.
///
/// This is identical to the schema in [rman-schema][rman-schema] and exists to provide a
/// persistent structure for the KeyEntry.
/// persistent structure for the `KeyEntry`.
///
/// [rman-schema]: https://github.com/ev3nvy/rman-schema
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2 changes: 1 addition & 1 deletion src/entries/language_entry.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::generated::rman::Language;
/// Single language entry object.
///
/// This is identical to the schema in [rman-schema][rman-schema] and exists to provide a
/// persistent structure for the LanguageEntry.
/// persistent structure for the `LanguageEntry`.
///
/// [rman-schema]: https://github.com/ev3nvy/rman-schema
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
2 changes: 1 addition & 1 deletion src/entries/param_entry.rs
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ use crate::generated::rman::Param;
/// Single param entry object.
///
/// This is identical to the schema in [rman-schema][rman-schema] and exists to provide a
/// persistent structure for the ParamEntry.
/// persistent structure for the `ParamEntry`.
///
/// [rman-schema]: https://github.com/ev3nvy/rman-schema
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
16 changes: 10 additions & 6 deletions src/file.rs
Original file line number Diff line number Diff line change
@@ -75,12 +75,12 @@ impl File {
chunk_entries: &HashMap<i64, (i64, u32, u32, u32)>,
) -> Result<Self> {
let id = file.id;
let name = file.name.to_owned();
let name = file.name.clone();
let permissions = file.permissions;
let size = file.size;
let symlink = file.symlink.to_owned();
let symlink = file.symlink.clone();
let language_mask = file.language_mask;
let chunk_ids = file.chunk_ids.to_owned();
let chunk_ids = &file.chunk_ids;

let mut directory_id = file.directory_id;
let mut path = String::new();
@@ -104,14 +104,14 @@ impl File {
}

if let Some(lang_name) = language_entries.get(&(i + 1)) {
languages.push(lang_name.to_owned());
languages.push(lang_name.clone());
}
}

let mut chunks = Vec::new();

for chunk_id in chunk_ids {
let Some(chunk) = chunk_entries.get(&chunk_id) else {
let Some(chunk) = chunk_entries.get(chunk_id) else {
let message = format!("Could not find a chunk with the following id: \"{chunk_id}\".");
return Err(ManifestError::FileParseError(message));
};
@@ -160,7 +160,11 @@ impl File {
/// # Examples
///
/// See [downloading a file](index.html#example-downloading-a-file).
pub async fn download<W: Write, U: IntoUrl>(&self, mut writer: W, bundle_url: U) -> Result<()> {
pub async fn download<W: Write + Send, U: IntoUrl + Send>(
&self,
mut writer: W,
bundle_url: U,
) -> Result<()> {
let client = Client::new();

for (bundle_id, offset, uncompressed_size, compressed_size) in &self.chunks {
5 changes: 3 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![deny(missing_docs)]
#![deny(missing_debug_implementations)]
#![deny(clippy::all, clippy::unwrap_used)]
#![deny(clippy::all, clippy::pedantic, clippy::nursery, clippy::unwrap_used)]
#![allow(clippy::module_name_repetitions, clippy::similar_names)]

//! # rman
//!
@@ -122,7 +123,7 @@
//! This crate:
//! - reads the `.manifest` file, and verifies it's a valid `rman` file,
//! - decompresses the containing data which was compressed using [zstd][zstd],
//! - parses the decompressed [FlatBuffer][flatbuffers] data,
//! - parses the decompressed [flatbuffer data][flatbuffers],
//! - stores all of the parsed data on [`ManifestData`][crate::ManifestData],
//! - combines the data into a vector of downloadable [`File`][crate::File]s,
//! - provides a function to [`download`][crate::File::download] specific files.
9 changes: 5 additions & 4 deletions src/parser/header.rs
Original file line number Diff line number Diff line change
@@ -68,11 +68,12 @@ impl Header {
/// [`version_error`](index.html#feature-version_error) is enabled, the error
/// [`InvalidMinor`][crate::ManifestError::InvalidMinor] is returned.
///
/// If offset is smaller or larger than the file, the error
/// If [`offset`](Header::offset) is smaller or larger than the file, the error
/// [`InvalidOffset`][crate::ManifestError::InvalidOffset] is returned.
///
/// If compressed_size is smaller or larger than the file, the error
/// [`CompressedSizeTooLarge`][crate::ManifestError::CompressedSizeTooLarge] is returned.
/// If [`compressed_size`](Header::compressed_size) is smaller or larger than the file, the
/// error [`CompressedSizeTooLarge`][crate::ManifestError::CompressedSizeTooLarge] is
/// returned.
pub fn from_reader<R>(reader: &mut R) -> Result<Self>
where
R: Read + Seek,
@@ -91,7 +92,7 @@ impl Header {

// N A M R (RMAN bacwards because I am reading this as an u32, instead
// of as an array of chars)
if magic != 0x4E414D52 {
if magic != 0x4E_41_4D_52 {
return Err(ManifestError::InvalidMagicBytes(magic));
}

4 changes: 2 additions & 2 deletions src/parser/manifest.rs
Original file line number Diff line number Diff line change
@@ -85,14 +85,14 @@ impl ManifestData {
fn map_languages(language_entries: &[LanguageEntry]) -> HashMap<u8, String> {
language_entries
.iter()
.map(|l| (l.id, l.name.to_owned()))
.map(|l| (l.id, l.name.clone()))
.collect()
}

fn map_directories(directory_entries: &[DirectoryEntry]) -> HashMap<i64, (String, i64)> {
directory_entries
.iter()
.map(|d| (d.id, (d.name.to_owned(), d.parent_id)))
.map(|d| (d.id, (d.name.clone(), d.parent_id)))
.collect()
}