Skip to content

Commit 44bc24a

Browse files
committed
style: rustfmt
1 parent 5de3765 commit 44bc24a

File tree

12 files changed

+50
-61
lines changed

12 files changed

+50
-61
lines changed

src/cli/manip.rs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ fn increase_weight(old_w: f64, inc_w: f64) -> f64 {
1818
fn decrease_weight(old_w: f64, dec_w: f64) -> f64 {
1919
let result = old_w - dec_w;
2020

21-
if result < 0.0 {
22-
0.0
23-
} else {
24-
result
25-
}
21+
if result < 0.0 { 0.0 } else { result }
2622
}
2723

2824

2925
fn do_increase<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
30-
where P: AsRef<path::Path> {
26+
where P: AsRef<path::Path>
27+
{
3128
let p = p.as_ref();
3229

3330
// don't process $HOME
@@ -54,7 +51,8 @@ fn do_increase<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
5451

5552

5653
fn do_increase_and_save<P>(config: &Config, p: P, w: f64) -> Entry
57-
where P: AsRef<path::Path> {
54+
where P: AsRef<path::Path>
55+
{
5856
let mut entries = data::load(config);
5957
let entry = do_increase(&mut entries, p, w);
6058
data::save(config, &entries).unwrap();
@@ -63,7 +61,8 @@ fn do_increase_and_save<P>(config: &Config, p: P, w: f64) -> Entry
6361

6462

6563
fn do_decrease<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
66-
where P: AsRef<path::Path> {
64+
where P: AsRef<path::Path>
65+
{
6766
let p = p.as_ref();
6867
for ent in entries.iter_mut() {
6968
if ent.path == p {
@@ -83,7 +82,8 @@ fn do_decrease<P>(entries: &mut Vec<Entry>, p: P, w: f64) -> Entry
8382

8483

8584
fn do_decrease_and_save<P>(config: &Config, p: P, w: f64) -> Entry
86-
where P: AsRef<path::Path> {
85+
where P: AsRef<path::Path>
86+
{
8787
let mut entries = data::load(config);
8888
let entry = do_decrease(&mut entries, p, w);
8989
data::save(config, &entries).unwrap();
@@ -92,7 +92,8 @@ fn do_decrease_and_save<P>(config: &Config, p: P, w: f64) -> Entry
9292

9393

9494
pub fn add<P>(config: &Config, p: P)
95-
where P: AsRef<path::Path> {
95+
where P: AsRef<path::Path>
96+
{
9697
do_increase_and_save(config, p, DEFAULT_INCREASE_WEIGHT as f64);
9798
}
9899

src/cli/query.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,7 @@ 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
42-
.into_iter()
41+
let result: Vec<_> = result.into_iter()
4342
.map(|p| p.to_string_lossy().into_owned())
4443
.collect();
4544
let strs: Vec<_> = result.iter().map(|p| p.as_str()).collect();
@@ -74,7 +73,8 @@ pub fn query(config: &Config, needles: Vec<String>) {
7473
fn prepare_query<'a>(needles: &'a [&'a str],
7574
check_existence: bool,
7675
count: usize,
77-
use_fallback: bool) -> Query<'a> {
76+
use_fallback: bool)
77+
-> Query<'a> {
7878
let mut count = count;
7979
let needles = if needles.is_empty() {
8080
vec![""]
@@ -140,8 +140,7 @@ fn do_query<'a>(config: &Config, query: QueryConfig<'a>) -> Vec<path::PathBuf> {
140140
Ok(cwd) => Some(cwd),
141141
Err(_) => None,
142142
};
143-
let result = result
144-
.filter(|p| {
143+
let result = result.filter(|p| {
145144
if cwd.is_some() {
146145
&p.path != cwd.as_ref().unwrap()
147146
} else {

src/data/datafile.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ fn load_backup(config: &Config) -> Vec<Entry> {
101101
fn save_to(file: &fs::File, data: &[Entry]) -> io::Result<()> {
102102
let mut writer = io::BufWriter::new(file);
103103
for entry in data.iter() {
104-
writeln!(&mut writer, "{}\t{}", entry.weight, entry.path.to_string_lossy())?;
104+
writeln!(&mut writer,
105+
"{}\t{}",
106+
entry.weight,
107+
entry.path.to_string_lossy())?;
105108
}
106109

107110
Ok(())
@@ -125,9 +128,7 @@ fn need_backup(config: &Config) -> io::Result<bool> {
125128
let mtime = metadata.modified()?;
126129

127130
match now.duration_since(mtime) {
128-
Ok(duration) => {
129-
Ok(duration.as_secs() > BACKUP_THRESHOLD)
130-
}
131+
Ok(duration) => Ok(duration.as_secs() > BACKUP_THRESHOLD),
131132
Err(_) => {
132133
// Clock skew: mtime is in the future!
133134
// TODO: print warning

src/data/entry.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ pub struct Entry {
1111

1212

1313
impl Entry {
14-
pub fn new<P>(path: P, weight: f64) -> Entry where P: Into<path::PathBuf> {
14+
pub fn new<P>(path: P, weight: f64) -> Entry
15+
where P: Into<path::PathBuf>
16+
{
1517
Entry {
1618
path: path.into(),
1719
weight: weight,
@@ -48,8 +50,7 @@ impl PartialEq for Entry {
4850
}
4951

5052

51-
impl Eq for Entry {
52-
}
53+
impl Eq for Entry {}
5354

5455

5556
impl Ord for Entry {

src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ pub const VERSION: &'static str = "0.1.0";
2424

2525

2626
/// Get a version string suitable for the CLI display.
27-
pub fn get_version_str(
28-
vcs_commit: Option<&str>,
29-
vcs_clean: Option<bool>
30-
) -> String {
27+
pub fn get_version_str(vcs_commit: Option<&str>, vcs_clean: Option<bool>) -> String {
3128
let mut tmp = String::new();
3229
tmp.push_str("autojump v");
3330
tmp.push_str(VERSION_TRACK);
@@ -50,4 +47,3 @@ pub fn get_version_str(
5047

5148
tmp
5249
}
53-

src/matcher/fuzzy.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ impl<'a> FuzzyMatcher<'a> {
3131
}
3232

3333

34-
pub fn filter_path<'p, P>(&'a self, paths: &'p [P]) -> impl iter::Iterator<Item=&'p P> + 'a
35-
where P: AsRef<path::Path>, 'p: 'a {
36-
paths
37-
.iter()
34+
pub fn filter_path<'p, P>(&'a self, paths: &'p [P]) -> impl iter::Iterator<Item = &'p P> + 'a
35+
where P: AsRef<path::Path>,
36+
'p: 'a
37+
{
38+
paths.iter()
3839
.map(|p| (p.as_ref().file_name(), p))
3940
.filter(|&(s, _)| s.is_some())
4041
.map(|(s, p)| (s.unwrap().to_string_lossy().into_owned(), p))

src/matcher/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,16 +41,10 @@ impl<'a> Matcher<'a> {
4141

4242
pub fn new(needles: Vec<&'a str>, ignore_case: bool) -> Matcher<'a> {
4343
let fuzzy_matcher = fuzzy::FuzzyMatcher::defaults(needles[needles.len() - 1]);
44-
let re_anywhere = re_based::prepare_regex(
45-
&needles,
46-
re_based::re_match_anywhere,
47-
ignore_case,
48-
);
49-
let re_consecutive = re_based::prepare_regex(
50-
&needles,
51-
re_based::re_match_consecutive,
52-
ignore_case,
53-
);
44+
let re_anywhere =
45+
re_based::prepare_regex(&needles, re_based::re_match_anywhere, ignore_case);
46+
let re_consecutive =
47+
re_based::prepare_regex(&needles, re_based::re_match_consecutive, ignore_case);
5448

5549
Matcher {
5650
fuzzy_matcher: fuzzy_matcher,
@@ -59,8 +53,10 @@ impl<'a> Matcher<'a> {
5953
}
6054
}
6155

62-
pub fn execute<'p, P>(&'a self, haystack: &'p [P]) -> impl iter::Iterator<Item=&'p P> + 'a
63-
where P: AsRef<path::Path>, 'p: 'a {
56+
pub fn execute<'p, P>(&'a self, haystack: &'p [P]) -> impl iter::Iterator<Item = &'p P> + 'a
57+
where P: AsRef<path::Path>,
58+
'p: 'a
59+
{
6460
// Iterator sadness...
6561
macro_rules! filter_path_with_re {
6662
($l: expr, $re: expr) => {

src/matcher/re_based.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,11 @@ 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 F: Fn(&[&str]) -> String
8+
{
89
let re = {
910
let mut tmp = String::new();
10-
tmp.push_str(if ignore_case {
11-
"(?iu)"
12-
} else {
13-
"(?u)"
14-
});
11+
tmp.push_str(if ignore_case { "(?iu)" } else { "(?u)" });
1512
tmp.push_str(&f(needles));
1613
tmp
1714
};
@@ -24,7 +21,7 @@ fn re_escape(s: &str) -> String {
2421
let mut result = String::with_capacity(s.len());
2522
for ch in s.chars() {
2623
match ch {
27-
'0' ... '9' | 'A' ... 'Z' | 'a' ... 'z' | '_' | '/' => result.push(ch),
24+
'0'...'9' | 'A'...'Z' | 'a'...'z' | '_' | '/' => result.push(ch),
2825
_ => {
2926
result.push_str(r"\x");
3027
// skip the r"\u" prefix and take the remaining "{xxxx}" part

src/matcher/tests.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg_attr(rustfmt, rustfmt_skip)]
2+
13
use std::path;
24

35
use super::*;

src/utils/input.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ 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> {
17-
needles
18-
.iter()
16+
where S: AsRef<str>
17+
{
18+
needles.iter()
1919
.map(|s| s.as_ref())
2020
.map(sanitize_one_needle)
2121
.collect()

0 commit comments

Comments
 (0)