Merge pull request #1446 from matthiasbeyer/travis-clippy

Travis: clippy
This commit is contained in:
Matthias Beyer 2018-04-26 10:25:45 +02:00 committed by GitHub
commit 0bacfb0a88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 77 additions and 108 deletions

View file

@ -143,7 +143,7 @@ pub trait TraceIterator<T, E> : Iterator<Item = Result<T, E>> + Sized {
fn unwrap_with<F>(self, f: F) -> UnwrapWith<Self, F>
where F: FnMut(E)
{
UnwrapWith { iter: self, f: f }
UnwrapWith { iter: self, f }
}
}

View file

@ -25,7 +25,7 @@ pub trait ErrFromStr<T> {
impl<T, E: Error> ErrFromStr<T> for Result<T, E> {
fn err_from_str(self) -> Result<T, String> {
self.map_err(|e| format!("{}", e.description()))
self.map_err(|e| e.description().to_string())
}
}

View file

@ -56,12 +56,12 @@ pub fn fetch_config(searchpath: &PathBuf) -> Result<Value> {
vec![
vec![searchpath.clone()],
gen_vars(searchpath.clone(), variants.clone(), &modifier),
gen_vars(searchpath, variants.clone(), &modifier),
env::var("HOME").map(|home| gen_vars(PathBuf::from(home), variants.clone(), &modifier))
env::var("HOME").map(|home| gen_vars(&PathBuf::from(home), variants.clone(), &modifier))
.unwrap_or(vec![]),
xdg_basedir::get_data_home().map(|data_dir| gen_vars(data_dir, variants.clone(), &modifier))
xdg_basedir::get_data_home().map(|data_dir| gen_vars(&data_dir, variants.clone(), &modifier))
.unwrap_or(vec![]),
].iter()
.flatten()

View file

@ -132,7 +132,7 @@ impl<'a> Runtime<'a> {
let store_result = if cli_app.use_inmemory_fs() {
Store::new_with_backend(storepath,
&config,
Box::new(InMemoryFileAbstraction::new()))
Box::new(InMemoryFileAbstraction::default()))
} else {
Store::new(storepath, &config)
};

View file

@ -31,7 +31,7 @@ pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bo
let key = "store.implicit-create";
if let Some(ref t) = *config {
t.read_bool(key)?.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))
t.read_bool(key)?.ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError(key)))
} else {
Ok(false)
}

View file

@ -105,15 +105,8 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
/// `FSFileAbstraction` state type
///
/// A lazy file is either absent, but a path to it is available, or it is present.
#[derive(Debug)]
pub struct FSFileAbstraction {
}
impl FSFileAbstraction {
pub fn new() -> FSFileAbstraction {
FSFileAbstraction { }
}
}
#[derive(Debug, Default)]
pub struct FSFileAbstraction {}
impl FileAbstraction for FSFileAbstraction {

View file

@ -71,7 +71,7 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
mtx.get_mut()
.get(&self.absent_path)
.cloned()
.ok_or(SE::from_kind(SEK::FileNotFound))
.ok_or_else(|| SE::from_kind(SEK::FileNotFound))
})
}
@ -87,19 +87,13 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
}
}
#[derive(Debug)]
#[derive(Debug, Default)]
pub struct InMemoryFileAbstraction {
virtual_filesystem: Backend,
}
impl InMemoryFileAbstraction {
pub fn new() -> InMemoryFileAbstraction {
InMemoryFileAbstraction {
virtual_filesystem: Arc::new(Mutex::new(RefCell::new(HashMap::new()))),
}
}
pub fn backend(&self) -> &Backend {
&self.virtual_filesystem
}
@ -123,7 +117,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
.get_mut()
.remove(path)
.map(|_| ())
.ok_or(SE::from_kind(SEK::FileNotFound))
.ok_or_else(|| SE::from_kind(SEK::FileNotFound))
}
fn copy(&self, from: &PathBuf, to: &PathBuf) -> Result<(), SE> {
@ -131,7 +125,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
let backend = mtx.get_mut();
let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?;
let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?;
backend.insert(to.clone(), a);
debug!("Copying: {:?} -> {:?} worked", from, to);
Ok(())
@ -142,7 +136,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
let backend = mtx.get_mut();
let a = backend.get(from).cloned().ok_or(SE::from_kind(SEK::FileNotFound))?;
let a = backend.get(from).cloned().ok_or_else(|| SE::from_kind(SEK::FileNotFound))?;
backend.insert(to.clone(), a);
debug!("Renaming: {:?} -> {:?} worked", from, to);
Ok(())

View file

@ -104,7 +104,7 @@ mod test {
#[test]
fn lazy_file() {
let fs = InMemoryFileAbstraction::new();
let fs = InMemoryFileAbstraction::default();
let mut path = PathBuf::from("tests");
path.set_file_name("test1");
@ -124,7 +124,7 @@ Hello World"#, env!("CARGO_PKG_VERSION"))).unwrap();
#[test]
fn lazy_file_multiline() {
let fs = InMemoryFileAbstraction::new();
let fs = InMemoryFileAbstraction::default();
let mut path = PathBuf::from("tests");
path.set_file_name("test1");
@ -145,7 +145,7 @@ baz"#, env!("CARGO_PKG_VERSION"))).unwrap();
#[test]
fn lazy_file_multiline_trailing_newlines() {
let fs = InMemoryFileAbstraction::new();
let fs = InMemoryFileAbstraction::default();
let mut path = PathBuf::from("tests");
path.set_file_name("test1");

View file

@ -131,7 +131,7 @@ impl Iterator for Walk {
}
}
return None;
None
}
}
@ -148,7 +148,7 @@ impl StoreEntry {
}
Ok(StoreEntry {
id: id,
id,
file: backend.new_instance(pb),
status: StoreEntryStatus::Present,
})
@ -235,7 +235,7 @@ impl Store {
/// - On success: Store object
///
pub fn new(location: PathBuf, store_config: &Option<Value>) -> Result<Store> {
let backend = Box::new(FSFileAbstraction::new());
let backend = Box::new(FSFileAbstraction::default());
Store::new_with_backend(location, store_config, backend)
}
@ -758,10 +758,7 @@ impl<'a> FileLockEntry<'a, > {
///
/// Only for internal use.
fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> {
FileLockEntry {
store: store,
entry: entry,
}
FileLockEntry { store, entry }
}
}
@ -796,12 +793,9 @@ impl<'a> Drop for FileLockEntry<'a> {
fn drop(&mut self) {
use libimagerror::trace::trace_error_dbg;
trace!("Dropping: {:?} - from FileLockEntry::drop()", self.get_location());
match self.store._update(self, true) {
Err(e) => {
if let Err(e) = self.store._update(self, true) {
trace_error_dbg(&e);
if_cfg_panic!("ERROR WHILE DROPPING: {:?}", e);
},
Ok(_) => { },
}
}
}
@ -883,8 +877,8 @@ impl Entry {
Ok(Entry {
location: loc.into_storeid()?,
header: header,
content: content,
header,
content,
})
}
@ -1010,13 +1004,13 @@ fn has_only_tables(t: &Value) -> Result<bool> {
fn has_main_section(t: &Value) -> Result<bool> {
t.read("imag")?
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag")))
.ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError("imag")))
.map(Value::is_table)
}
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
t.read_string("imag.version")?
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
.ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
.map(String::from)
.map(|s| ::semver::Version::parse(&s).is_ok())
}
@ -1182,7 +1176,7 @@ mod store_tests {
use file_abstraction::InMemoryFileAbstraction;
pub fn get_store() -> Store {
let backend = Box::new(InMemoryFileAbstraction::new());
let backend = Box::new(InMemoryFileAbstraction::default());
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}
@ -1367,7 +1361,7 @@ mod store_tests {
use file_abstraction::InMemoryFileAbstraction;
let mut store = {
let backend = InMemoryFileAbstraction::new();
let backend = InMemoryFileAbstraction::default();
let backend = Box::new(backend);
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
@ -1383,7 +1377,7 @@ mod store_tests {
}
{
let other_backend = InMemoryFileAbstraction::new();
let other_backend = InMemoryFileAbstraction::default();
let other_backend = Box::new(other_backend);
assert!(store.reset_backend(other_backend).is_ok())

View file

@ -80,7 +80,7 @@ impl StoreId {
debug!("Building Storeid object baseless");
Ok(StoreId {
base: None,
id: id
id
})
}
}
@ -116,7 +116,7 @@ impl StoreId {
.unwrap_or_else(|| self.id.clone())
.to_str()
.map(String::from)
.ok_or(SE::from_kind(SEK::StoreIdHandlingError))
.ok_or_else(|| SE::from_kind(SEK::StoreIdHandlingError))
}
/// Returns the components of the `id` part of the StoreId object.
@ -255,9 +255,7 @@ impl Debug for StoreIdIterator {
impl StoreIdIterator {
pub fn new(iter: Box<Iterator<Item = StoreId>>) -> StoreIdIterator {
StoreIdIterator {
iter: iter,
}
StoreIdIterator { iter }
}
}

View file

@ -46,26 +46,22 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
let mut content = String::new();
let mut header_consumed = false;
let mut iter = buf.split("\n").skip(1).peekable(); // the first line is "---"
let mut iter = buf.split('\n').skip(1).peekable(); // the first line is "---"
while let Some(line) = iter.next() {
if line == "---" && !header_consumed {
header_consumed = true;
// do not further process the line
} else {
if !header_consumed {
} else if !header_consumed {
let _ = writeln!(header, "{}", line)?;
} else {
if iter.peek().is_some() {
} else if iter.peek().is_some() {
let _ = writeln!(content, "{}", line)?;
} else {
let _ = write!(content, "{}", line)?;
}
}
}
}
Ok((Value::parse(&header)?, String::from(content)))
Ok((Value::parse(&header)?, content))
}
#[cfg(test)]

View file

@ -37,7 +37,7 @@ mod test {
use std::path::PathBuf;
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
let backend = Box::new(InMemoryFileAbstraction::default());
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}

View file

@ -127,7 +127,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::store::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
let backend = Box::new(InMemoryFileAbstraction::default());
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}

View file

@ -207,7 +207,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::store::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
let backend = Box::new(InMemoryFileAbstraction::default());
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}

View file

@ -113,7 +113,7 @@ mod tests {
fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
let backend = Box::new(InMemoryFileAbstraction::default());
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}

View file

@ -416,7 +416,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
let backend = Box::new(InMemoryFileAbstraction::default());
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}

View file

@ -784,7 +784,7 @@ mod test {
pub fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let backend = Box::new(InMemoryFileAbstraction::new());
let backend = Box::new(InMemoryFileAbstraction::default());
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
}

View file

@ -243,7 +243,7 @@ mod tests {
pub fn get_store() -> Store {
use libimagstore::file_abstraction::InMemoryFileAbstraction;
let fs = InMemoryFileAbstraction::new();
let fs = InMemoryFileAbstraction::default();
Store::new_with_backend(PathBuf::from("/"), &None, Box::new(fs)).unwrap()
}

View file

@ -44,7 +44,7 @@ pub mod err {
impl ErrorNotification {
pub fn new(trace: usize, timeout: i32) -> ErrorNotification {
let notif = Notification {
timeout: timeout,
timeout,
message: String::new(), // Not used in this special case
summary: "[Error]".to_owned(),
urgency: Urgency::High,
@ -62,7 +62,7 @@ pub mod err {
let mut n = RustNotification::new();
n.appname("imag");
n.summary("[Error]");
n.urgency(urgency.clone());
n.urgency(urgency);
n.body(e.description());
try!(n.finalize().show().map(|_| ()).chain_err(|| NEK::Unknown));

View file

@ -30,11 +30,7 @@ pub struct Date {
impl Date {
pub fn new(year: i32, month: u32, day: u32) -> Date {
Date {
year: year,
month: month,
day: day,
}
Date { year, month, day }
}
pub fn year(&self) -> i32 {

View file

@ -31,10 +31,7 @@ pub struct DateTime {
impl DateTime {
pub fn new(date: Date, time: Time) -> DateTime {
DateTime {
date: date,
time: time
}
DateTime { date, time }
}
pub fn date(&self) -> &Date {

View file

@ -30,11 +30,7 @@ pub struct Time {
impl Time {
pub fn new(hour: u32, minute: u32, second: u32) -> Time {
Time {
hour: hour,
minute: minute,
second: second
}
Time { hour, minute, second }
}
pub fn hour(&self) -> u32 {

View file

@ -23,27 +23,27 @@
use std::path::PathBuf;
use boolinator::Boolinator;
pub fn is_existing_path(s: String) -> Result<(), String> {
PathBuf::from(s.clone()).exists().as_result((), format!("Not a File or Directory: {}", s))
pub fn is_existing_path<A: AsRef<str>>(s: A) -> Result<(), String> {
PathBuf::from(s.as_ref()).exists().as_result((), format!("Not a File or Directory: {}", s.as_ref()))
}
pub fn is_file(s: String) -> Result<(), String> {
PathBuf::from(s.clone()).is_file().as_result((), format!("Not a File: {}", s))
pub fn is_file<A: AsRef<str>>(s: A) -> Result<(), String> {
PathBuf::from(s.as_ref()).is_file().as_result((), format!("Not a File: {}", s.as_ref()))
}
pub fn is_directory(s: String) -> Result<(), String> {
PathBuf::from(s.clone()).is_dir().as_result((), format!("Not a Directory: {}", s))
pub fn is_directory<A: AsRef<str>>(s: A) -> Result<(), String> {
PathBuf::from(s.as_ref()).is_dir().as_result((), format!("Not a Directory: {}", s.as_ref()))
}
pub fn is_integer(s: String) -> Result<(), String> {
pub fn is_integer<A: AsRef<str>>(s: A) -> Result<(), String> {
use std::str::FromStr;
let i : Result<i64, _> = FromStr::from_str(&s);
i.map(|_| ()).map_err(|_| format!("Not an integer: {}", s))
let i : Result<i64, _> = FromStr::from_str(s.as_ref());
i.map(|_| ()).map_err(|_| format!("Not an integer: {}", s.as_ref()))
}
pub fn is_url(s: String) -> Result<(), String> {
pub fn is_url<A: AsRef<str>>(s: A) -> Result<(), String> {
use url::Url;
Url::parse(&s).map(|_| ()).map_err(|_| format!("Not a URL: {}", s))
Url::parse(s.as_ref()).map(|_| ()).map_err(|_| format!("Not a URL: {}", s.as_ref()))
}

View file

@ -21,7 +21,7 @@ use chrono::NaiveDate;
use chrono::NaiveDateTime;
use chrono::format::ParseError;
pub const NAIVE_DATE_STRING_FORMAT : &'static str = "%Y-%m-%d";
pub const NAIVE_DATE_STRING_FORMAT : &str = "%Y-%m-%d";
pub fn date_to_string(ndt: &NaiveDate) -> String {
ndt.format(NAIVE_DATE_STRING_FORMAT).to_string()
@ -33,7 +33,7 @@ pub fn date_from_string<S>(s: S) -> Result<NaiveDate, ParseError>
NaiveDate::parse_from_str(s.as_ref(), NAIVE_DATE_STRING_FORMAT)
}
pub const NAIVE_DATETIME_STRING_FORMAT : &'static str = "%Y-%m-%d %H:%M:%S";
pub const NAIVE_DATETIME_STRING_FORMAT : &str = "%Y-%m-%d %H:%M:%S";
pub fn datetime_to_string(ndt: &NaiveDateTime) -> String {
ndt.format(NAIVE_DATETIME_STRING_FORMAT).to_string()

View file

@ -33,7 +33,7 @@ pub struct KeyValue<K, V> {
impl<K, V> KeyValue<K, V> {
pub fn new(k: K, v: V) -> KeyValue<K, V> {
KeyValue { k: k, v: v }
KeyValue { k, v }
}
pub fn key(&self) -> &K {
@ -75,7 +75,12 @@ impl IntoKeyValue<String, String> for String {
.unwrap();
}
R.captures(&self[..])
.map(|c| c.name("VALUE").or(c.name("QVALUE")).map(|m| m.as_str()).unwrap_or(""))
.map(|c| {
c.name("VALUE")
.or_else(|| c.name("QVALUE"))
.map(|m| m.as_str())
.unwrap_or("")
})
};
key.and_then(|k| {

View file

@ -32,12 +32,12 @@
* ```
*
*/
pub fn generate_variants<A, B, C, F>(base: A, modders: Vec<B>, f: &F)
pub fn generate_variants<A, B, C, F>(base: &A, modders: Vec<B>, f: &F)
-> Vec<C>
where
F: Fn(&A, B) -> C
{
modders.into_iter().map(|m| f(&base, m)).collect()
modders.into_iter().map(|m| f(base, m)).collect()
}
#[cfg(test)]
@ -49,7 +49,7 @@ mod test {
fn test_variants_simple() {
let base = 1;
let vars = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
let res = generate_variants(base, vars, &|base, var| base + var);
let res = generate_variants(&base, vars, &|base, var| base + var);
assert!(res.len() == 11, format!("Length is {} instead of 11", res.len()));
assert!(res.iter().all(|i| *i > 0));
@ -62,7 +62,7 @@ mod test {
let base = PathBuf::from("/");
let vars = vec!["foo", "bar", "baz"];
let res = generate_variants(base, vars, &|base, var| {
let res = generate_variants(&base, vars, &|base, var| {
let mut base = base.clone();
base.push(var);
base