Skip to content

Commit

Permalink
Merge pull request #226 from figsoda/fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
figsoda committed Jun 16, 2023
2 parents af3f163 + e7311ef commit 73d96c8
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 46 deletions.
9 changes: 9 additions & 0 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -320,7 +320,7 @@ fn next_matching_line<M: Matcher<Error = NoError>>(
// 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 {
Expand All @@ -329,8 +329,7 @@ fn next_matching_line<M: Matcher<Error = NoError>>(
};

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
Expand Down
37 changes: 7 additions & 30 deletions src/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -116,35 +116,21 @@ impl<T> FileNode<T> {
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,
}
Expand Down Expand Up @@ -178,21 +164,15 @@ 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),
}),
b'd' => str::from_utf8(buf)
.ok()
.and_then(|s| s.parse().ok())
.map(|size| Directory {
size,
contents: (),
}),
.map(|size| Directory { size, contents: () }),
_ => None,
})
}
Expand Down Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/frcode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ impl ResizableBuf {

impl Deref for ResizableBuf {
type Target = [u8];

fn deref(&self) -> &[u8] {
&self.data
}
Expand Down
12 changes: 4 additions & 8 deletions src/hydra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<Fetcher> {
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.
Expand Down Expand Up @@ -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,
}))
};
Expand Down
6 changes: 3 additions & 3 deletions src/listings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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);
},
}
};
}

Expand Down
1 change: 1 addition & 0 deletions src/nixpkgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ impl PackagesQuery<ChildStdout> {

impl Iterator for PackagesQuery<ChildStdout> {
type Item = Result<StorePath, Error>;

fn next(&mut self) -> Option<Self::Item> {
if let Err(e) = self.ensure_initialized() {
return Some(Err(e));
Expand Down

0 comments on commit 73d96c8

Please sign in to comment.