diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 2da5cb3..226ed2e 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -22,3 +22,12 @@ jobs: run: cargo build --verbose - name: Run tests run: cargo test --verbose + + format: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Cargo fmt + run: | + rustup toolchain install nightly --profile minimal -c rustfmt + cargo +nightly fmt --check diff --git a/rustfmt.toml b/rustfmt.toml index 38b9e24..accb88a 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,7 @@ -reorder_imports = true +unstable_features = true + group_imports = "StdExternalCrate" +newline_style = "Unix" +reorder_impl_items = true +use_field_init_shorthand = true +use_try_shorthand = true diff --git a/src/database.rs b/src/database.rs index 57a8efe..cdfc18b 100644 --- a/src/database.rs +++ b/src/database.rs @@ -8,8 +8,8 @@ use std::path::Path; use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt}; use error_chain::error_chain; -use grep::matcher::{LineMatchKind, Match, Matcher, NoError}; use grep; +use grep::matcher::{LineMatchKind, Match, Matcher, NoError}; use memchr::{memchr, memrchr}; use regex::bytes::Regex; use regex_syntax::ast::{ @@ -320,7 +320,7 @@ fn next_matching_line>( // for an empty "line" at the end of the buffer // since this is not a line match, return None if start == buf.len() { - return None + return None; }; let (pos, confirmed) = match candidate { @@ -329,8 +329,7 @@ fn next_matching_line>( }; let line_start = memrchr(b'\n', &buf[..pos]).map_or(0, |x| x + 1); - let line_end = memchr(b'\n', &buf[pos..]) - .map_or(buf.len(), |x| x + pos + 1); + let line_end = memchr(b'\n', &buf[pos..]).map_or(buf.len(), |x| x + pos + 1); if !confirmed && !matcher diff --git a/src/files.rs b/src/files.rs index 4da576b..a010253 100644 --- a/src/files.rs +++ b/src/files.rs @@ -6,8 +6,8 @@ use std::collections::HashMap; use std::io::{self, Write}; use std::str::{self, FromStr}; -use clap::ValueEnum; use clap::builder::PossibleValue; +use clap::ValueEnum; use memchr::memchr; use serde::{Deserialize, Serialize}; use serde_bytes::ByteBuf; @@ -116,35 +116,21 @@ impl FileNode { pub fn split_contents(&self) -> (FileNode<()>, Option<&T>) { use self::FileNode::*; match *self { - Regular { size, executable } => ( - Regular { - size, - executable, - }, - None, - ), + Regular { size, executable } => (Regular { size, executable }, None), Symlink { ref target } => ( Symlink { target: target.clone(), }, None, ), - Directory { size, ref contents } => ( - Directory { - size, - contents: (), - }, - Some(contents), - ), + Directory { size, ref contents } => (Directory { size, contents: () }, Some(contents)), } } /// Return the type of this file. pub fn get_type(&self) -> FileType { match *self { - FileNode::Regular { executable, .. } => FileType::Regular { - executable, - }, + FileNode::Regular { executable, .. } => FileType::Regular { executable }, FileNode::Directory { .. } => FileType::Directory, FileNode::Symlink { .. } => FileType::Symlink, } @@ -178,10 +164,7 @@ impl FileNode<()> { str::from_utf8(buf) .ok() .and_then(|s| s.parse().ok()) - .map(|size| Regular { - executable, - size, - }) + .map(|size| Regular { executable, size }) } b's' => Some(Symlink { target: ByteBuf::from(buf), @@ -189,10 +172,7 @@ impl FileNode<()> { b'd' => str::from_utf8(buf) .ok() .and_then(|s| s.parse().ok()) - .map(|size| Directory { - size, - contents: (), - }), + .map(|size| Directory { size, contents: () }), _ => None, }) } @@ -235,10 +215,7 @@ impl FileTreeEntry { impl FileTree { pub fn regular(size: u64, executable: bool) -> Self { - FileTree(FileNode::Regular { - size, - executable, - }) + FileTree(FileNode::Regular { size, executable }) } pub fn symlink(target: ByteBuf) -> Self { diff --git a/src/frcode.rs b/src/frcode.rs index d9af283..d20bbb7 100644 --- a/src/frcode.rs +++ b/src/frcode.rs @@ -126,6 +126,7 @@ impl ResizableBuf { impl Deref for ResizableBuf { type Target = [u8]; + fn deref(&self) -> &[u8] { &self.data } diff --git a/src/hydra.rs b/src/hydra.rs index b908c23..3a9949a 100644 --- a/src/hydra.rs +++ b/src/hydra.rs @@ -12,6 +12,7 @@ use std::pin::Pin; use std::result; use std::str::{self, FromStr, Utf8Error}; use std::time::{Duration, Instant}; + use brotli_decompressor::BrotliDecompress; use error_chain::error_chain; use futures::future::{self, Either}; @@ -219,10 +220,7 @@ impl Fetcher { /// `cache_url` specifies the URL of the binary cache (example: `https://cache.nixos.org`). pub fn new(cache_url: String) -> Result { let client = Client::new()?; - Ok(Fetcher { - client, - cache_url, - }) + Ok(Fetcher { client, cache_url }) } /// Sends a GET request to the given URL and decodes the response with the given encoding. @@ -398,10 +396,8 @@ impl Fetcher { Ok(Some(ParsedNAR { store_path: path, - nar_path: nar_path.ok_or(ErrorKind::ParseStorePath( - url, - "no URL line found".into(), - ))?, + nar_path: nar_path + .ok_or(ErrorKind::ParseStorePath(url, "no URL line found".into()))?, references: result, })) }; diff --git a/src/listings.rs b/src/listings.rs index 4d91c5e..3daef3a 100644 --- a/src/listings.rs +++ b/src/listings.rs @@ -4,8 +4,8 @@ use std::iter::FromIterator; use std::pin::Pin; use futures::{future, FutureExt, Stream, StreamExt, TryFutureExt}; -use indexmap::IndexMap; use indexmap::map::Entry; +use indexmap::IndexMap; use rayon::prelude::{IntoParallelRefIterator, ParallelIterator}; use crate::errors::{Error, ErrorKind, Result, ResultExt}; @@ -65,10 +65,10 @@ fn fetch_listings_impl( if e.get().origin().attr.len() > path.origin().attr.len() { e.insert(path); } - }, + } Entry::Vacant(e) => { e.insert(path); - }, + } }; } diff --git a/src/nixpkgs.rs b/src/nixpkgs.rs index 5de496d..d20ec83 100644 --- a/src/nixpkgs.rs +++ b/src/nixpkgs.rs @@ -123,6 +123,7 @@ impl PackagesQuery { impl Iterator for PackagesQuery { type Item = Result; + fn next(&mut self) -> Option { if let Err(e) = self.ensure_initialized() { return Some(Err(e));