Skip to content

Commit 73d96c8

Browse files
authored
Merge pull request #226 from figsoda/fmt
2 parents af3f163 + e7311ef commit 73d96c8

File tree

8 files changed

+34
-46
lines changed

8 files changed

+34
-46
lines changed

.github/workflows/rust.yml

+9
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,12 @@ jobs:
2222
run: cargo build --verbose
2323
- name: Run tests
2424
run: cargo test --verbose
25+
26+
format:
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v3
30+
- name: Cargo fmt
31+
run: |
32+
rustup toolchain install nightly --profile minimal -c rustfmt
33+
cargo +nightly fmt --check

rustfmt.toml

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
1-
reorder_imports = true
1+
unstable_features = true
2+
23
group_imports = "StdExternalCrate"
4+
newline_style = "Unix"
5+
reorder_impl_items = true
6+
use_field_init_shorthand = true
7+
use_try_shorthand = true

src/database.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ use std::path::Path;
88

99
use byteorder::{LittleEndian, ReadBytesExt, WriteBytesExt};
1010
use error_chain::error_chain;
11-
use grep::matcher::{LineMatchKind, Match, Matcher, NoError};
1211
use grep;
12+
use grep::matcher::{LineMatchKind, Match, Matcher, NoError};
1313
use memchr::{memchr, memrchr};
1414
use regex::bytes::Regex;
1515
use regex_syntax::ast::{
@@ -320,7 +320,7 @@ fn next_matching_line<M: Matcher<Error = NoError>>(
320320
// for an empty "line" at the end of the buffer
321321
// since this is not a line match, return None
322322
if start == buf.len() {
323-
return None
323+
return None;
324324
};
325325

326326
let (pos, confirmed) = match candidate {
@@ -329,8 +329,7 @@ fn next_matching_line<M: Matcher<Error = NoError>>(
329329
};
330330

331331
let line_start = memrchr(b'\n', &buf[..pos]).map_or(0, |x| x + 1);
332-
let line_end = memchr(b'\n', &buf[pos..])
333-
.map_or(buf.len(), |x| x + pos + 1);
332+
let line_end = memchr(b'\n', &buf[pos..]).map_or(buf.len(), |x| x + pos + 1);
334333

335334
if !confirmed
336335
&& !matcher

src/files.rs

+7-30
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ use std::collections::HashMap;
66
use std::io::{self, Write};
77
use std::str::{self, FromStr};
88

9-
use clap::ValueEnum;
109
use clap::builder::PossibleValue;
10+
use clap::ValueEnum;
1111
use memchr::memchr;
1212
use serde::{Deserialize, Serialize};
1313
use serde_bytes::ByteBuf;
@@ -116,35 +116,21 @@ impl<T> FileNode<T> {
116116
pub fn split_contents(&self) -> (FileNode<()>, Option<&T>) {
117117
use self::FileNode::*;
118118
match *self {
119-
Regular { size, executable } => (
120-
Regular {
121-
size,
122-
executable,
123-
},
124-
None,
125-
),
119+
Regular { size, executable } => (Regular { size, executable }, None),
126120
Symlink { ref target } => (
127121
Symlink {
128122
target: target.clone(),
129123
},
130124
None,
131125
),
132-
Directory { size, ref contents } => (
133-
Directory {
134-
size,
135-
contents: (),
136-
},
137-
Some(contents),
138-
),
126+
Directory { size, ref contents } => (Directory { size, contents: () }, Some(contents)),
139127
}
140128
}
141129

142130
/// Return the type of this file.
143131
pub fn get_type(&self) -> FileType {
144132
match *self {
145-
FileNode::Regular { executable, .. } => FileType::Regular {
146-
executable,
147-
},
133+
FileNode::Regular { executable, .. } => FileType::Regular { executable },
148134
FileNode::Directory { .. } => FileType::Directory,
149135
FileNode::Symlink { .. } => FileType::Symlink,
150136
}
@@ -178,21 +164,15 @@ impl FileNode<()> {
178164
str::from_utf8(buf)
179165
.ok()
180166
.and_then(|s| s.parse().ok())
181-
.map(|size| Regular {
182-
executable,
183-
size,
184-
})
167+
.map(|size| Regular { executable, size })
185168
}
186169
b's' => Some(Symlink {
187170
target: ByteBuf::from(buf),
188171
}),
189172
b'd' => str::from_utf8(buf)
190173
.ok()
191174
.and_then(|s| s.parse().ok())
192-
.map(|size| Directory {
193-
size,
194-
contents: (),
195-
}),
175+
.map(|size| Directory { size, contents: () }),
196176
_ => None,
197177
})
198178
}
@@ -235,10 +215,7 @@ impl FileTreeEntry {
235215

236216
impl FileTree {
237217
pub fn regular(size: u64, executable: bool) -> Self {
238-
FileTree(FileNode::Regular {
239-
size,
240-
executable,
241-
})
218+
FileTree(FileNode::Regular { size, executable })
242219
}
243220

244221
pub fn symlink(target: ByteBuf) -> Self {

src/frcode.rs

+1
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ impl ResizableBuf {
126126

127127
impl Deref for ResizableBuf {
128128
type Target = [u8];
129+
129130
fn deref(&self) -> &[u8] {
130131
&self.data
131132
}

src/hydra.rs

+4-8
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use std::pin::Pin;
1212
use std::result;
1313
use std::str::{self, FromStr, Utf8Error};
1414
use std::time::{Duration, Instant};
15+
1516
use brotli_decompressor::BrotliDecompress;
1617
use error_chain::error_chain;
1718
use futures::future::{self, Either};
@@ -219,10 +220,7 @@ impl Fetcher {
219220
/// `cache_url` specifies the URL of the binary cache (example: `https://cache.nixos.org`).
220221
pub fn new(cache_url: String) -> Result<Fetcher> {
221222
let client = Client::new()?;
222-
Ok(Fetcher {
223-
client,
224-
cache_url,
225-
})
223+
Ok(Fetcher { client, cache_url })
226224
}
227225

228226
/// Sends a GET request to the given URL and decodes the response with the given encoding.
@@ -398,10 +396,8 @@ impl Fetcher {
398396

399397
Ok(Some(ParsedNAR {
400398
store_path: path,
401-
nar_path: nar_path.ok_or(ErrorKind::ParseStorePath(
402-
url,
403-
"no URL line found".into(),
404-
))?,
399+
nar_path: nar_path
400+
.ok_or(ErrorKind::ParseStorePath(url, "no URL line found".into()))?,
405401
references: result,
406402
}))
407403
};

src/listings.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ use std::iter::FromIterator;
44
use std::pin::Pin;
55

66
use futures::{future, FutureExt, Stream, StreamExt, TryFutureExt};
7-
use indexmap::IndexMap;
87
use indexmap::map::Entry;
8+
use indexmap::IndexMap;
99
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
1010

1111
use crate::errors::{Error, ErrorKind, Result, ResultExt};
@@ -65,10 +65,10 @@ fn fetch_listings_impl(
6565
if e.get().origin().attr.len() > path.origin().attr.len() {
6666
e.insert(path);
6767
}
68-
},
68+
}
6969
Entry::Vacant(e) => {
7070
e.insert(path);
71-
},
71+
}
7272
};
7373
}
7474

src/nixpkgs.rs

+1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ impl PackagesQuery<ChildStdout> {
123123

124124
impl Iterator for PackagesQuery<ChildStdout> {
125125
type Item = Result<StorePath, Error>;
126+
126127
fn next(&mut self) -> Option<Self::Item> {
127128
if let Err(e) = self.ensure_initialized() {
128129
return Some(Err(e));

0 commit comments

Comments
 (0)