Skip to content

Commit 6c20950

Browse files
committed
style: rustfmt
1 parent 5f5ac68 commit 6c20950

File tree

11 files changed

+80
-60
lines changed

11 files changed

+80
-60
lines changed

src/cli/manip.rs

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ fn decrease_weight(old_w: f64, dec_w: f64) -> f64 {
2323

2424

2525
fn do_increase<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
26-
where P: AsRef<path::Path>
26+
where
27+
P: AsRef<path::Path>,
2728
{
2829
let p = p.as_ref();
2930

@@ -51,7 +52,8 @@ fn do_increase<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
5152

5253

5354
fn do_increase_and_save<P>(config: &Config, p: P, w: f64) -> Entry
54-
where P: AsRef<path::Path>
55+
where
56+
P: AsRef<path::Path>,
5557
{
5658
let mut entries = data::load(config);
5759
let entry = do_increase(&mut entries, p, w);
@@ -61,7 +63,8 @@ fn do_increase_and_save<P>(config: &Config, p: P, w: f64) -> Entry
6163

6264

6365
fn do_decrease<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
64-
where P: AsRef<path::Path>
66+
where
67+
P: AsRef<path::Path>,
6568
{
6669
let p = p.as_ref();
6770
for ent in entries.iter_mut() {
@@ -75,14 +78,15 @@ fn do_decrease<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
7578
// TODO: original impl also adds an entry in case the requested path is
7679
// absent, but is it desirable?
7780
// For now let's mimic its behavior...
78-
let entry = Entry::new(p, 0.0); // no need to compare
81+
let entry = Entry::new(p, 0.0); // no need to compare
7982
entries.push(entry.clone());
8083
entry
8184
}
8285

8386

8487
fn do_decrease_and_save<P>(config: &Config, p: P, w: f64) -> Entry
85-
where P: AsRef<path::Path>
88+
where
89+
P: AsRef<path::Path>,
8690
{
8791
let mut entries = data::load(config);
8892
let entry = do_decrease(&mut entries, p, w);
@@ -92,7 +96,8 @@ fn do_decrease_and_save<P>(config: &Config, p: P, w: f64) -> Entry
9296

9397

9498
pub fn add<P>(config: &Config, p: P)
95-
where P: AsRef<path::Path>
99+
where
100+
P: AsRef<path::Path>,
96101
{
97102
do_increase_and_save(config, p, DEFAULT_INCREASE_WEIGHT as f64);
98103
}

src/cli/purge.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ use super::super::data;
55
pub fn purge(config: &Config) {
66
let entries = data::load(config);
77
let old_len = entries.len();
8-
let entries: Vec<_> = entries.into_iter()
8+
let entries: Vec<_> = entries
9+
.into_iter()
910
.filter(|ent| ent.path.exists())
1011
.collect();
1112

src/cli/query.rs

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub fn complete(config: &Config, needles: Vec<String>) {
3838
let real_needle = query.needles[0].clone();
3939
let result = do_query(config, query);
4040
// Convert to `&str` for tab entry info creation.
41-
let result: Vec<_> = result.into_iter()
41+
let result: Vec<_> = result
42+
.into_iter()
4243
.map(|p| p.to_string_lossy().into_owned())
4344
.collect();
4445
let strs: Vec<_> = result.iter().map(|p| p.as_str()).collect();
@@ -70,11 +71,12 @@ pub fn query(config: &Config, needles: Vec<String>) {
7071
}
7172

7273

73-
fn prepare_query<'a>(needles: &'a [&'a str],
74-
check_existence: bool,
75-
count: usize,
76-
use_fallback: bool)
77-
-> Query<'a> {
74+
fn prepare_query<'a>(
75+
needles: &'a [&'a str],
76+
check_existence: bool,
77+
count: usize,
78+
use_fallback: bool,
79+
) -> Query<'a> {
7880
let mut count = count;
7981
let needles = if needles.is_empty() {
8082
vec![""]
@@ -140,19 +142,16 @@ fn do_query<'a>(config: &Config, query: QueryConfig<'a>) -> Vec<path::PathBuf> {
140142
Ok(cwd) => Some(cwd),
141143
Err(_) => None,
142144
};
143-
let result = result.filter(|p| {
144-
if cwd.is_some() {
145-
&p.path != cwd.as_ref().unwrap()
146-
} else {
147-
true
148-
}
145+
let result = result
146+
.filter(|p| if cwd.is_some() {
147+
&p.path != cwd.as_ref().unwrap()
148+
} else {
149+
true
149150
})
150-
.filter(|p| {
151-
if check_existence {
152-
p.path.exists()
153-
} else {
154-
true
155-
}
151+
.filter(|p| if check_existence {
152+
p.path.exists()
153+
} else {
154+
true
156155
});
157156

158157
// Always return something for shell in case index is out-of-bounds.

src/data/datafile.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@ use super::super::Config;
1010
use super::entry::Entry;
1111

1212

13-
const BACKUP_THRESHOLD: u64 = 24 * 60 * 60; // 1 d
13+
const BACKUP_THRESHOLD: u64 = 24 * 60 * 60; // 1 d
1414

1515

1616
#[cfg(target_os = "macos")]
1717
fn migrate_osx_xdg_data(config: &Config) -> io::Result<()> {
1818
let xdg_aj_home = super::super::xdg_home_hardcoded();
1919
if !xdg_aj_home.exists() {
20-
return Ok(())
20+
return Ok(());
2121
}
2222

2323
let old_config = Config::from_prefix(&xdg_aj_home);
@@ -102,10 +102,12 @@ fn load_backup(config: &Config) -> Vec<Entry> {
102102
fn save_to(file: &fs::File, data: &[Entry]) -> io::Result<()> {
103103
let mut writer = io::BufWriter::new(file);
104104
for entry in data.iter() {
105-
writeln!(&mut writer,
106-
"{}\t{}",
107-
entry.weight,
108-
entry.path.to_string_lossy())?;
105+
writeln!(
106+
&mut writer,
107+
"{}\t{}",
108+
entry.weight,
109+
entry.path.to_string_lossy()
110+
)?;
109111
}
110112

111113
Ok(())

src/data/entry.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ pub struct Entry {
1212

1313
impl Entry {
1414
pub fn new<P>(path: P, weight: f64) -> Entry
15-
where P: Into<path::PathBuf>
15+
where
16+
P: Into<path::PathBuf>,
1617
{
1718
Entry {
1819
path: path.into(),

src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,3 @@ pub const VERSION_TRACK: &'static str = "22.5.0";
2424

2525
/// The library's version.
2626
pub const VERSION: &'static str = "0.2.2";
27-

src/matcher/fuzzy.rs

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,12 @@ impl<'a> FuzzyMatcher<'a> {
3333

3434
#[cfg(feature = "nightly")]
3535
pub fn filter_path<'p, P>(&'a self, paths: &'p [P]) -> impl iter::Iterator<Item = &'p P> + 'a
36-
where P: AsRef<path::Path>,
37-
'p: 'a
36+
where
37+
P: AsRef<path::Path>,
38+
'p: 'a,
3839
{
39-
paths.iter()
40+
paths
41+
.iter()
4042
.map(|p| (p.as_ref().file_name(), p))
4143
.filter(|&(s, _)| s.is_some())
4244
.map(|(s, p)| (s.unwrap().to_string_lossy().into_owned(), p))
@@ -48,15 +50,19 @@ impl<'a> FuzzyMatcher<'a> {
4850

4951
#[cfg(not(feature = "nightly"))]
5052
pub fn filter_path<'p, P>(&'a self, paths: &'p [P]) -> Box<iter::Iterator<Item = &'p P> + 'a>
51-
where P: AsRef<path::Path>,
52-
'p: 'a
53+
where
54+
P: AsRef<path::Path>,
55+
'p: 'a,
5356
{
54-
Box::new(paths.iter()
55-
.map(|p| (p.as_ref().file_name(), p))
56-
.filter(|&(s, _)| s.is_some())
57-
.map(|(s, p)| (s.unwrap().to_string_lossy().into_owned(), p))
58-
.map(move |(s, p)| (strsim::jaro_winkler(self.needle, &s), p))
59-
.filter(move |&(sim, _)| sim >= self.threshold)
60-
.map(|(_, p)| p))
57+
Box::new(
58+
paths
59+
.iter()
60+
.map(|p| (p.as_ref().file_name(), p))
61+
.filter(|&(s, _)| s.is_some())
62+
.map(|(s, p)| (s.unwrap().to_string_lossy().into_owned(), p))
63+
.map(move |(s, p)| (strsim::jaro_winkler(self.needle, &s), p))
64+
.filter(move |&(sim, _)| sim >= self.threshold)
65+
.map(|(_, p)| p),
66+
)
6167
}
6268
}

src/matcher/mod.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,9 @@ impl<'a> Matcher<'a> {
6868

6969
#[cfg(feature = "nightly")]
7070
pub fn execute<'p, P>(&'a self, haystack: &'p [P]) -> impl iter::Iterator<Item = &'p P> + 'a
71-
where P: AsRef<path::Path>,
72-
'p: 'a
71+
where
72+
P: AsRef<path::Path>,
73+
'p: 'a,
7374
{
7475
filter_path_with_re!(haystack, self.re_consecutive)
7576
.chain(self.fuzzy_matcher.filter_path(haystack))
@@ -79,11 +80,14 @@ impl<'a> Matcher<'a> {
7980

8081
#[cfg(not(feature = "nightly"))]
8182
pub fn execute<'p, P>(&'a self, haystack: &'p [P]) -> Box<iter::Iterator<Item = &'p P> + 'a>
82-
where P: AsRef<path::Path>,
83-
'p: 'a
83+
where
84+
P: AsRef<path::Path>,
85+
'p: 'a,
8486
{
85-
Box::new(filter_path_with_re!(haystack, self.re_consecutive)
86-
.chain(self.fuzzy_matcher.filter_path(haystack))
87-
.chain(filter_path_with_re!(haystack, self.re_anywhere)))
87+
Box::new(
88+
filter_path_with_re!(haystack, self.re_consecutive)
89+
.chain(self.fuzzy_matcher.filter_path(haystack))
90+
.chain(filter_path_with_re!(haystack, self.re_anywhere)),
91+
)
8892
}
8993
}

src/matcher/re_based.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use regex;
44

55

66
pub fn prepare_regex<F>(needles: &[&str], f: F, ignore_case: bool) -> regex::Regex
7-
where F: Fn(&[&str]) -> String
7+
where
8+
F: Fn(&[&str]) -> String,
89
{
910
let re = {
1011
let mut tmp = String::new();

src/utils/input.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ fn sanitize_one_needle(needle: &str) -> &str {
1313

1414

1515
pub fn sanitize<'a, S>(needles: &'a [S]) -> Vec<&'a str>
16-
where S: AsRef<str>
16+
where
17+
S: AsRef<str>,
1718
{
18-
needles.iter()
19+
needles
20+
.iter()
1921
.map(|s| s.as_ref())
2022
.map(sanitize_one_needle)
2123
.collect()

0 commit comments

Comments
 (0)