summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYorhel <git@yorhel.nl>2020-05-20 16:26:54 +0200
committerYorhel <git@yorhel.nl>2020-05-20 16:26:54 +0200
commit77e80fe2111afd8be1104c90d110e55ba2c1baed (patch)
tree802dafa881faae5b19661efef79cc755568458be
parenta619f4374d90f43f5bf079bfcdc70dbbe8458c85 (diff)
cargo clippy fixes
-rw-r--r--src/config.rs8
-rw-r--r--src/fields/ffprobe.rs2
-rw-r--r--src/main.rs2
-rw-r--r--src/packs.rs22
-rw-r--r--src/scan.rs9
5 files changed, 21 insertions, 22 deletions
diff --git a/src/config.rs b/src/config.rs
index 59186bf..f9f1efa 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -108,7 +108,7 @@ fn parse_qstr<'a>(line: &Line, s: &mut &'a str) -> Result<String> {
Err(line.err(ErrorKind::Local(format!("Unterminated {}", chr))))
} else {
- let i = s.find(|c:char| c.is_whitespace()).unwrap_or(s.len());
+ let i = s.find(|c:char| c.is_whitespace()).unwrap_or_else(|| s.len());
let v = (&s[..i]).to_string();
*s = &s[i..];
Ok(v)
@@ -161,15 +161,15 @@ impl Config {
let path = parse_qstr(&line, &mut s)?;
let path_s = path.trim_end_matches('/');
if path_s.is_empty() {
- return Err(line.err(ErrorKind::Local(format!("Invalid path, expected syntax: 'Share /virtual/path /actual/path'"))));
+ return Err(line.err(ErrorKind::Local("Invalid path, expected syntax: 'Share /virtual/path /actual/path'".to_string())));
}
if !s.trim().is_empty() {
- return Err(line.err(ErrorKind::Local(format!("Unexpected trailing arguments to 'Share'"))));
+ return Err(line.err(ErrorKind::Local("Unexpected trailing arguments to 'Share'".to_string())));
}
if self.share.0.contains_key(mount_s.as_str()) {
return Err(line.err(ErrorKind::Local(format!("Duplicate Share: {}", mount_s))));
}
- self.share.0.insert(mount_s.to_string().into_boxed_str(), path_s.to_string().into_boxed_str());
+ self.share.0.insert(mount_s.into_boxed_str(), path_s.to_string().into_boxed_str());
Ok(())
}
diff --git a/src/fields/ffprobe.rs b/src/fields/ffprobe.rs
index 80cd065..3e010b7 100644
--- a/src/fields/ffprobe.rs
+++ b/src/fields/ffprobe.rs
@@ -278,7 +278,7 @@ fn normalize(buf: &str, out: &mut Fields) {
let mut split = key.trim_start_matches("streams.stream.").splitn(2, '.');
if let Some(idx) = split.next().and_then(|v| v.parse::<usize>().ok()) {
if let Some(subkey) = split.next() {
- streams.entry(idx).or_insert(HashMap::new()).insert(subkey.to_string(), parse_val(val));
+ streams.entry(idx).or_insert_with(HashMap::new).insert(subkey.to_string(), parse_val(val));
}
}
} else {
diff --git a/src/main.rs b/src/main.rs
index ccb305a..411165f 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,4 +1,4 @@
-#![allow(clippy::mutex_atomic, clippy::type_complexity, clippy::redundant_field_names)]
+#![allow(clippy::mutex_atomic, clippy::redundant_field_names, clippy::option_option)]
#[macro_use] extern crate log;
diff --git a/src/packs.rs b/src/packs.rs
index 5e92856..fad46aa 100644
--- a/src/packs.rs
+++ b/src/packs.rs
@@ -59,7 +59,7 @@ const PACK_CACHE : usize = 2;
fn i64_encoded_len(mut n: i64) -> usize {
let mut l = 1;
if n < 0 { l += 1; n = n.saturating_mul(-1); }
- while n >= 10 { l += 1; n = n / 10; }
+ while n >= 10 { l += 1; n /= 10; }
l
}
@@ -267,13 +267,13 @@ impl Packs {
/// be marked as dirty and the pack will be marked for deletion.
fn mod_file<F>(&mut self, db: &Connection, hash: Hash, func: F) where F: FnOnce(Option<Box<File>>) -> Option<Box<File>> {
let old = self.files.take(&hash);
- let old_pack = old.as_ref().and_then(|f| f.pack.clone());
+ let old_pack = old.as_ref().and_then(|f| f.pack);
if old_pack.is_none() {
self.dirty_size -= old.as_ref().map_or(0, |f| f.encoded_len());
}
let new = func(old);
- let new_pack = new.as_ref().and_then(|f| f.pack.clone());
+ let new_pack = new.as_ref().and_then(|f| f.pack);
if new.is_some() && new_pack.is_none() {
self.dirty_size += new.as_ref().map_or(0, |f| f.encoded_len());
@@ -326,8 +326,8 @@ impl Packs {
assert!(!files.is_empty());
for mut f in files.into_iter() {
- f.pack = Some(pack.clone());
- let h = f.blake3.clone();
+ f.pack = Some(*pack);
+ let h = f.blake3;
self.mod_file(db, h, move |_| Some(Box::new(f)))
}
trace!("Read pack {} in {}ms", pack.to_hex(), (Instant::now()-t_start).as_secs_f32()*1000.);
@@ -390,7 +390,7 @@ impl Packs {
let mut q = db.prepare("SELECT pack FROM paths WHERE hash = ? AND pack IS NOT NULL LIMIT 1").unwrap();
q.bind(1, &hash.as_bytes()[..]).unwrap();
if q.next().unwrap() == sqlite::State::Row {
- let pack = read_hash(&mut q, 0).unwrap();
+ let pack = read_hash(&q, 0).unwrap();
self.read_pack(conf, db, &pack);
}
}
@@ -436,13 +436,13 @@ impl Packs {
q.reset().unwrap();
self.read_pack(conf, db, &pack);
- let files : Vec<Hash> = self.packs.get(&pack).unwrap().iter().map(|h| h.clone()).collect();
+ let files : Vec<Hash> = self.packs.get(&pack).unwrap().iter().copied().collect();
for h in files {
self.mod_file(db, h.clone(), |mf| mf.and_then(|mut f| {
// The extra allocations here are silly...
let oldpaths = std::mem::replace(&mut f.paths, BTreeSet::new());
let oldlen = oldpaths.len();
- f.paths = oldpaths.into_iter().filter(|path| db_index.contains(&(h.clone(), path.to_string()))).collect();
+ f.paths = oldpaths.into_iter().filter(|path| db_index.contains(&(h, path.to_string()))).collect();
let newlen = f.paths.len();
if newlen != oldlen {
f.pack = None;
@@ -516,7 +516,7 @@ impl Packs {
let t_start = Instant::now();
let mut files : Vec<(usize,Hash)> =
self.dirty.iter()
- .map(|h| (self.files.get(h).unwrap().encoded_len(), h.clone()))
+ .map(|h| (self.files.get(h).unwrap().encoded_len(), *h))
.collect();
files.sort_unstable_by(|(sa,ha),(sb,hb)| sb.cmp(sa).then_with(|| ha.as_bytes().cmp(hb.as_bytes())));
@@ -571,7 +571,7 @@ impl Packs {
let smallest_file = self.dirty.iter().map(|h| self.files.get(h).unwrap().encoded_len()).min().unwrap();
q.bind(1, PACK_SIZE_MIN.min(PACK_SIZE_MAX - smallest_file - 10) as i64).unwrap();
if q.next().unwrap() == sqlite::State::Row {
- let pack = read_hash(&mut q, 0).unwrap();
+ let pack = read_hash(&q, 0).unwrap();
q.reset().unwrap();
trace!("Merging dirty files with {}", pack.to_hex());
self.read_pack(conf, db, &pack);
@@ -597,7 +597,7 @@ impl Packs {
let mut buf = io::BufWriter::new(fs::File::create(&tmppath).unwrap());
let mut q = db.prepare("SELECT pack FROM packs ORDER BY pack").unwrap();
while q.next().unwrap() == sqlite::State::Row {
- let pack = read_hash(&mut q, 0).unwrap();
+ let pack = read_hash(&q, 0).unwrap();
hasher.update(&pack.as_bytes()[..]);
buf.write_all(&pack.as_bytes()[..]).unwrap();
}
diff --git a/src/scan.rs b/src/scan.rs
index 567aafd..d1e2c3d 100644
--- a/src/scan.rs
+++ b/src/scan.rs
@@ -27,7 +27,7 @@ pub fn scan(store: &Store) {
};
scan.walk_dir(
&mut String::new(),
- &mut store.config().share.fspath("").unwrap_or(String::new()),
+ &mut store.config().share.fspath("").unwrap_or_default(),
&share_tree(&store.config().share)
);
store.scan_finalize();
@@ -184,13 +184,12 @@ impl Scan<'_> {
let e = if sub.0.is_empty() {
vpath.truncate(orig_v);
vpath.push_str(name);
- let e = self.read_entry(vpath, self.store.config().share.as_ref().get(&vpath[..]).unwrap());
- e
+ self.read_entry(vpath, self.store.config().share.as_ref().get(&vpath[..]).unwrap())
} else {
Some(None)
};
if let Some(e) = e {
- entries.push((name.to_string(), e));
+ entries.push(((*name).to_string(), e));
}
}
@@ -217,7 +216,7 @@ impl Scan<'_> {
let mut subfspath = if subtree.is_none() {
format!("{}{}", &fspath, &dir)
} else {
- self.store.config().share.as_ref().get(&subvpath[..]).map(|v| v.to_string()).unwrap_or(String::new())
+ self.store.config().share.as_ref().get(&subvpath[..]).map(|v| v.to_string()).unwrap_or_default()
};
self.walk_dir(
&mut subvpath,