diff --git a/.drone.yml b/.drone.yml index 8dde10d..b401997 100644 --- a/.drone.yml +++ b/.drone.yml @@ -4,7 +4,11 @@ type: docker name: default steps: -- name: build +- name: linux-gnu image: rust:latest commands: - cargo test -j3 +- name: linux-musl + image: rust:alpine + commands: + - cargo test -j3 diff --git a/clippy.sh b/clippy.sh index 1b13eb3..78a3a58 100755 --- a/clippy.sh +++ b/clippy.sh @@ -8,7 +8,7 @@ cargo clippy -- \ -W clippy::cargo \ -A clippy::unused_io_amount \ -A clippy::redundant_closure_for_method_calls \ - -A clippy::shadow_unrelated \ + -A clippy::shadow_unrelated # ALLOWS: # unused_io_amount: there are two places where i want to read up to X bytes and i'm fine with getting less than that diff --git a/src/extension_set.rs b/src/extension_set.rs index 7583296..27ffa77 100644 --- a/src/extension_set.rs +++ b/src/extension_set.rs @@ -19,7 +19,7 @@ pub enum ExtensionSet { } impl ExtensionSet { - /// The list of known extensions for this ExtensionSet. + /// The list of known extensions for this `ExtensionSet`. pub fn extensions(&self) -> Vec<&str> { match self { Self::Images => mime_guess::get_mime_extensions_str("image/*").unwrap().to_vec(), diff --git a/src/findings.rs b/src/findings.rs index 05df884..2fbbee1 100644 --- a/src/findings.rs +++ b/src/findings.rs @@ -1,7 +1,7 @@ use std::path::PathBuf; use mime_guess::Mime; -use smartstring::alias::*; +use smartstring::alias::String; use crate::inspectors::mime_extension_lookup; diff --git a/src/formats.rs b/src/formats.rs index c669852..a6b8d59 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -3,7 +3,7 @@ use std::io::{self, Write}; #[cfg(unix)] use std::os::unix::ffi::OsStrExt; -use std::path::{Path}; +use std::path::Path; use snailquote::escape; diff --git a/src/inspectors.rs b/src/inspectors.rs index 6812589..613c7bf 100644 --- a/src/inspectors.rs +++ b/src/inspectors.rs @@ -14,12 +14,12 @@ use crate::mime_db::MimeDb; /// The number of bytes to read initially. /// -/// Rather than reading the entire file all at once into a [BUF_SIZE] buffer, it tends to be faster to read a small +/// Rather than reading the entire file all at once into a [`BUF_SIZE`] buffer, it tends to be faster to read a small /// chunk of the file and trying to identify that, proceeding with the larger buffer if that fails. Many file formats /// can be identified with the first few dozen bytes, so the "happy path" will likely be taken in the majority of cases. const INITIAL_BUF_SIZE: usize = 128; -/// The number of bytes to read if the file couldn't be identified from its first [INITIAL_BUF_SIZE] bytes. +/// The number of bytes to read if the file couldn't be identified from its first [`INITIAL_BUF_SIZE`] bytes. const BUF_SIZE: usize = 4096; /// Tries to identify the mimetype of a file from a given path. diff --git a/src/main.rs b/src/main.rs index 2b63ae6..185a98c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -189,20 +189,20 @@ fn wanted_file(entry: &DirEntry, exts: &[&str], scan_opts: &ScanOpts) -> bool { exts.contains(&ext.unwrap().to_lowercase().as_str()) } -/// Given a file path, returns its extension, using [std::path::Path::extension]. +/// Given a file path, returns its extension, using [`std::path::Path::extension`]. /// /// The extension is currently [converted to a lossy string](std::ffi::OsStr::to_string_lossy), although it will -/// (eventually) in future return an OsStr instead. +/// (eventually) in future return an `OsStr` instead. // TODO: ↑ fn extension_from_path(path: &Path) -> Option { path.extension(). // Get the path's extension map(|e| String::from(e.to_string_lossy())) // Convert from OsStr to String } -/// Inspects the given entry, returning a [Findings] on success and a [ScanError] on failure. +/// Inspects the given entry, returning a [`Findings`] on success and a [`ScanError`] on failure. /// -/// In the event of an IO error, the returned ScanError will be of type [ScanError::File]. Otherwise, a -/// [ScanError::Mime] will be returned, meaning that the file was scanned successfully, but a mimetype could not be +/// In the event of an IO error, the returned [`ScanError`] will be of type [`ScanError::File`]. Otherwise, a +/// [`ScanError::Mime`] will be returned, meaning that the file was scanned successfully, but a mimetype could not be /// determined. fn scan_file(entry: &DirEntry) -> Result { // try to determine mimetype for this entry @@ -242,7 +242,7 @@ fn scan_file(entry: &DirEntry) -> Result { }) } -/// Takes a slice of [DirEntry]s and calls [scan_file] on each one, returning the results in a vector. +/// Takes a slice of [`DirEntry`]s and calls [`scan_file`] on each one, returning the results in a vector. fn scan_from_walkdir(entries: &[DirEntry]) -> Vec> { cfg_if! { if #[cfg(feature = "multi-threaded")] { @@ -264,9 +264,9 @@ fn scan_from_walkdir(entries: &[DirEntry]) -> Vec> { } } -/// Scans a given directory with [WalkDir], filters with [wanted_file], checks for errors, and returns a vector of +/// Scans a given directory with [`WalkDir`], filters with [`wanted_file`], checks for errors, and returns a vector of /// [DirEntry]s. -fn scan_directory(dirs: &PathBuf, exts: &Vec<&str>, scan_opts: &ScanOpts) -> Option> { +fn scan_directory(dirs: &PathBuf, exts: &[&str], scan_opts: &ScanOpts) -> Option> { let stepper = WalkDir::new(dirs).into_iter(); let mut probably_fatal_error = false; let entries: Vec = stepper diff --git a/src/parameters.rs b/src/parameters.rs index a095954..6524513 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -3,7 +3,7 @@ use std::path::PathBuf; use crate::extension_set::ExtensionSet; -use clap::{Clap, AppSettings}; +use clap::{AppSettings, Clap}; use smartstring::{LazyCompact, SmartString}; #[derive(Clap, PartialEq, Debug)] @@ -66,7 +66,7 @@ pub struct ScanOpts { /// Whether hidden files and directories should be scanned. pub hidden: bool, /// Whether files without extensions should be scanned. - pub extensionless: bool + pub extensionless: bool, } impl Parameters { @@ -83,7 +83,10 @@ impl Parameters { } } - pub fn get_scan_opts(&self) -> ScanOpts { - ScanOpts { hidden: self.scan_hidden, extensionless: self.scan_extensionless } + pub const fn get_scan_opts(&self) -> ScanOpts { + ScanOpts { + hidden: self.scan_hidden, + extensionless: self.scan_extensionless, + } } } diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 7290164..d1dfd4a 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -95,9 +95,9 @@ fn simple_directory() { drop(file); } - let scan_opts = ScanOpts{ + let scan_opts = ScanOpts { hidden: true, - extensionless: false + extensionless: false, }; let entries = scan_directory(