Merge pull request #1446 from matthiasbeyer/travis-clippy
Travis: clippy
This commit is contained in:
commit
0bacfb0a88
26 changed files with 77 additions and 108 deletions
|
@ -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>
|
fn unwrap_with<F>(self, f: F) -> UnwrapWith<Self, F>
|
||||||
where F: FnMut(E)
|
where F: FnMut(E)
|
||||||
{
|
{
|
||||||
UnwrapWith { iter: self, f: f }
|
UnwrapWith { iter: self, f }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ pub trait ErrFromStr<T> {
|
||||||
|
|
||||||
impl<T, E: Error> ErrFromStr<T> for Result<T, E> {
|
impl<T, E: Error> ErrFromStr<T> for Result<T, E> {
|
||||||
fn err_from_str(self) -> Result<T, String> {
|
fn err_from_str(self) -> Result<T, String> {
|
||||||
self.map_err(|e| format!("{}", e.description()))
|
self.map_err(|e| e.description().to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,12 +56,12 @@ pub fn fetch_config(searchpath: &PathBuf) -> Result<Value> {
|
||||||
|
|
||||||
vec![
|
vec![
|
||||||
vec![searchpath.clone()],
|
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![]),
|
.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![]),
|
.unwrap_or(vec![]),
|
||||||
].iter()
|
].iter()
|
||||||
.flatten()
|
.flatten()
|
||||||
|
|
|
@ -132,7 +132,7 @@ impl<'a> Runtime<'a> {
|
||||||
let store_result = if cli_app.use_inmemory_fs() {
|
let store_result = if cli_app.use_inmemory_fs() {
|
||||||
Store::new_with_backend(storepath,
|
Store::new_with_backend(storepath,
|
||||||
&config,
|
&config,
|
||||||
Box::new(InMemoryFileAbstraction::new()))
|
Box::new(InMemoryFileAbstraction::default()))
|
||||||
} else {
|
} else {
|
||||||
Store::new(storepath, &config)
|
Store::new(storepath, &config)
|
||||||
};
|
};
|
||||||
|
|
|
@ -31,7 +31,7 @@ pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bo
|
||||||
let key = "store.implicit-create";
|
let key = "store.implicit-create";
|
||||||
|
|
||||||
if let Some(ref t) = *config {
|
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 {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -105,15 +105,8 @@ impl FileAbstractionInstance for FSFileAbstractionInstance {
|
||||||
/// `FSFileAbstraction` state type
|
/// `FSFileAbstraction` state type
|
||||||
///
|
///
|
||||||
/// A lazy file is either absent, but a path to it is available, or it is present.
|
/// A lazy file is either absent, but a path to it is available, or it is present.
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
pub struct FSFileAbstraction {
|
pub struct FSFileAbstraction {}
|
||||||
}
|
|
||||||
|
|
||||||
impl FSFileAbstraction {
|
|
||||||
pub fn new() -> FSFileAbstraction {
|
|
||||||
FSFileAbstraction { }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl FileAbstraction for FSFileAbstraction {
|
impl FileAbstraction for FSFileAbstraction {
|
||||||
|
|
||||||
|
|
|
@ -71,7 +71,7 @@ impl FileAbstractionInstance for InMemoryFileAbstractionInstance {
|
||||||
mtx.get_mut()
|
mtx.get_mut()
|
||||||
.get(&self.absent_path)
|
.get(&self.absent_path)
|
||||||
.cloned()
|
.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 {
|
pub struct InMemoryFileAbstraction {
|
||||||
virtual_filesystem: Backend,
|
virtual_filesystem: Backend,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InMemoryFileAbstraction {
|
impl InMemoryFileAbstraction {
|
||||||
|
|
||||||
pub fn new() -> InMemoryFileAbstraction {
|
|
||||||
InMemoryFileAbstraction {
|
|
||||||
virtual_filesystem: Arc::new(Mutex::new(RefCell::new(HashMap::new()))),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn backend(&self) -> &Backend {
|
pub fn backend(&self) -> &Backend {
|
||||||
&self.virtual_filesystem
|
&self.virtual_filesystem
|
||||||
}
|
}
|
||||||
|
@ -123,7 +117,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
.get_mut()
|
.get_mut()
|
||||||
.remove(path)
|
.remove(path)
|
||||||
.map(|_| ())
|
.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> {
|
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 mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
||||||
let backend = mtx.get_mut();
|
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);
|
backend.insert(to.clone(), a);
|
||||||
debug!("Copying: {:?} -> {:?} worked", from, to);
|
debug!("Copying: {:?} -> {:?} worked", from, to);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -142,7 +136,7 @@ impl FileAbstraction for InMemoryFileAbstraction {
|
||||||
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
let mut mtx = self.backend().lock().expect("Locking Mutex failed");
|
||||||
let backend = mtx.get_mut();
|
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);
|
backend.insert(to.clone(), a);
|
||||||
debug!("Renaming: {:?} -> {:?} worked", from, to);
|
debug!("Renaming: {:?} -> {:?} worked", from, to);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -104,7 +104,7 @@ mod test {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lazy_file() {
|
fn lazy_file() {
|
||||||
let fs = InMemoryFileAbstraction::new();
|
let fs = InMemoryFileAbstraction::default();
|
||||||
|
|
||||||
let mut path = PathBuf::from("tests");
|
let mut path = PathBuf::from("tests");
|
||||||
path.set_file_name("test1");
|
path.set_file_name("test1");
|
||||||
|
@ -124,7 +124,7 @@ Hello World"#, env!("CARGO_PKG_VERSION"))).unwrap();
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lazy_file_multiline() {
|
fn lazy_file_multiline() {
|
||||||
let fs = InMemoryFileAbstraction::new();
|
let fs = InMemoryFileAbstraction::default();
|
||||||
|
|
||||||
let mut path = PathBuf::from("tests");
|
let mut path = PathBuf::from("tests");
|
||||||
path.set_file_name("test1");
|
path.set_file_name("test1");
|
||||||
|
@ -145,7 +145,7 @@ baz"#, env!("CARGO_PKG_VERSION"))).unwrap();
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn lazy_file_multiline_trailing_newlines() {
|
fn lazy_file_multiline_trailing_newlines() {
|
||||||
let fs = InMemoryFileAbstraction::new();
|
let fs = InMemoryFileAbstraction::default();
|
||||||
|
|
||||||
let mut path = PathBuf::from("tests");
|
let mut path = PathBuf::from("tests");
|
||||||
path.set_file_name("test1");
|
path.set_file_name("test1");
|
||||||
|
|
|
@ -131,7 +131,7 @@ impl Iterator for Walk {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return None;
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,7 +148,7 @@ impl StoreEntry {
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(StoreEntry {
|
Ok(StoreEntry {
|
||||||
id: id,
|
id,
|
||||||
file: backend.new_instance(pb),
|
file: backend.new_instance(pb),
|
||||||
status: StoreEntryStatus::Present,
|
status: StoreEntryStatus::Present,
|
||||||
})
|
})
|
||||||
|
@ -235,7 +235,7 @@ impl Store {
|
||||||
/// - On success: Store object
|
/// - On success: Store object
|
||||||
///
|
///
|
||||||
pub fn new(location: PathBuf, store_config: &Option<Value>) -> Result<Store> {
|
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)
|
Store::new_with_backend(location, store_config, backend)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -758,10 +758,7 @@ impl<'a> FileLockEntry<'a, > {
|
||||||
///
|
///
|
||||||
/// Only for internal use.
|
/// Only for internal use.
|
||||||
fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> {
|
fn new(store: &'a Store, entry: Entry) -> FileLockEntry<'a> {
|
||||||
FileLockEntry {
|
FileLockEntry { store, entry }
|
||||||
store: store,
|
|
||||||
entry: entry,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -796,12 +793,9 @@ impl<'a> Drop for FileLockEntry<'a> {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
use libimagerror::trace::trace_error_dbg;
|
use libimagerror::trace::trace_error_dbg;
|
||||||
trace!("Dropping: {:?} - from FileLockEntry::drop()", self.get_location());
|
trace!("Dropping: {:?} - from FileLockEntry::drop()", self.get_location());
|
||||||
match self.store._update(self, true) {
|
if let Err(e) = self.store._update(self, true) {
|
||||||
Err(e) => {
|
|
||||||
trace_error_dbg(&e);
|
trace_error_dbg(&e);
|
||||||
if_cfg_panic!("ERROR WHILE DROPPING: {:?}", e);
|
if_cfg_panic!("ERROR WHILE DROPPING: {:?}", e);
|
||||||
},
|
|
||||||
Ok(_) => { },
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -883,8 +877,8 @@ impl Entry {
|
||||||
|
|
||||||
Ok(Entry {
|
Ok(Entry {
|
||||||
location: loc.into_storeid()?,
|
location: loc.into_storeid()?,
|
||||||
header: header,
|
header,
|
||||||
content: content,
|
content,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1010,13 +1004,13 @@ fn has_only_tables(t: &Value) -> Result<bool> {
|
||||||
|
|
||||||
fn has_main_section(t: &Value) -> Result<bool> {
|
fn has_main_section(t: &Value) -> Result<bool> {
|
||||||
t.read("imag")?
|
t.read("imag")?
|
||||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag")))
|
.ok_or_else(|| SE::from_kind(SEK::ConfigKeyMissingError("imag")))
|
||||||
.map(Value::is_table)
|
.map(Value::is_table)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
|
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
|
||||||
t.read_string("imag.version")?
|
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(String::from)
|
||||||
.map(|s| ::semver::Version::parse(&s).is_ok())
|
.map(|s| ::semver::Version::parse(&s).is_ok())
|
||||||
}
|
}
|
||||||
|
@ -1182,7 +1176,7 @@ mod store_tests {
|
||||||
use file_abstraction::InMemoryFileAbstraction;
|
use file_abstraction::InMemoryFileAbstraction;
|
||||||
|
|
||||||
pub fn get_store() -> Store {
|
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()
|
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1367,7 +1361,7 @@ mod store_tests {
|
||||||
use file_abstraction::InMemoryFileAbstraction;
|
use file_abstraction::InMemoryFileAbstraction;
|
||||||
|
|
||||||
let mut store = {
|
let mut store = {
|
||||||
let backend = InMemoryFileAbstraction::new();
|
let backend = InMemoryFileAbstraction::default();
|
||||||
let backend = Box::new(backend);
|
let backend = Box::new(backend);
|
||||||
|
|
||||||
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
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);
|
let other_backend = Box::new(other_backend);
|
||||||
|
|
||||||
assert!(store.reset_backend(other_backend).is_ok())
|
assert!(store.reset_backend(other_backend).is_ok())
|
||||||
|
|
|
@ -80,7 +80,7 @@ impl StoreId {
|
||||||
debug!("Building Storeid object baseless");
|
debug!("Building Storeid object baseless");
|
||||||
Ok(StoreId {
|
Ok(StoreId {
|
||||||
base: None,
|
base: None,
|
||||||
id: id
|
id
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,7 @@ impl StoreId {
|
||||||
.unwrap_or_else(|| self.id.clone())
|
.unwrap_or_else(|| self.id.clone())
|
||||||
.to_str()
|
.to_str()
|
||||||
.map(String::from)
|
.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.
|
/// Returns the components of the `id` part of the StoreId object.
|
||||||
|
@ -255,9 +255,7 @@ impl Debug for StoreIdIterator {
|
||||||
impl StoreIdIterator {
|
impl StoreIdIterator {
|
||||||
|
|
||||||
pub fn new(iter: Box<Iterator<Item = StoreId>>) -> StoreIdIterator {
|
pub fn new(iter: Box<Iterator<Item = StoreId>>) -> StoreIdIterator {
|
||||||
StoreIdIterator {
|
StoreIdIterator { iter }
|
||||||
iter: iter,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,26 +46,22 @@ pub fn entry_buffer_to_header_content(buf: &str) -> Result<(Value, String)> {
|
||||||
let mut content = String::new();
|
let mut content = String::new();
|
||||||
let mut header_consumed = false;
|
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() {
|
while let Some(line) = iter.next() {
|
||||||
if line == "---" && !header_consumed {
|
if line == "---" && !header_consumed {
|
||||||
header_consumed = true;
|
header_consumed = true;
|
||||||
// do not further process the line
|
// do not further process the line
|
||||||
} else {
|
} else if !header_consumed {
|
||||||
if !header_consumed {
|
|
||||||
let _ = writeln!(header, "{}", line)?;
|
let _ = writeln!(header, "{}", line)?;
|
||||||
} else {
|
} else if iter.peek().is_some() {
|
||||||
if iter.peek().is_some() {
|
|
||||||
let _ = writeln!(content, "{}", line)?;
|
let _ = writeln!(content, "{}", line)?;
|
||||||
} else {
|
} else {
|
||||||
let _ = write!(content, "{}", line)?;
|
let _ = write!(content, "{}", line)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok((Value::parse(&header)?, String::from(content)))
|
Ok((Value::parse(&header)?, content))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
|
|
@ -37,7 +37,7 @@ mod test {
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
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()
|
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -127,7 +127,7 @@ mod tests {
|
||||||
|
|
||||||
pub fn get_store() -> Store {
|
pub fn get_store() -> Store {
|
||||||
use libimagstore::store::InMemoryFileAbstraction;
|
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()
|
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -207,7 +207,7 @@ mod tests {
|
||||||
|
|
||||||
pub fn get_store() -> Store {
|
pub fn get_store() -> Store {
|
||||||
use libimagstore::store::InMemoryFileAbstraction;
|
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()
|
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -113,7 +113,7 @@ mod tests {
|
||||||
|
|
||||||
fn get_store() -> Store {
|
fn get_store() -> Store {
|
||||||
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
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()
|
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -416,7 +416,7 @@ mod tests {
|
||||||
|
|
||||||
pub fn get_store() -> Store {
|
pub fn get_store() -> Store {
|
||||||
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
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()
|
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -784,7 +784,7 @@ mod test {
|
||||||
|
|
||||||
pub fn get_store() -> Store {
|
pub fn get_store() -> Store {
|
||||||
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
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()
|
Store::new_with_backend(PathBuf::from("/"), &None, backend).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,7 +243,7 @@ mod tests {
|
||||||
|
|
||||||
pub fn get_store() -> Store {
|
pub fn get_store() -> Store {
|
||||||
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
use libimagstore::file_abstraction::InMemoryFileAbstraction;
|
||||||
let fs = InMemoryFileAbstraction::new();
|
let fs = InMemoryFileAbstraction::default();
|
||||||
Store::new_with_backend(PathBuf::from("/"), &None, Box::new(fs)).unwrap()
|
Store::new_with_backend(PathBuf::from("/"), &None, Box::new(fs)).unwrap()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -44,7 +44,7 @@ pub mod err {
|
||||||
impl ErrorNotification {
|
impl ErrorNotification {
|
||||||
pub fn new(trace: usize, timeout: i32) -> ErrorNotification {
|
pub fn new(trace: usize, timeout: i32) -> ErrorNotification {
|
||||||
let notif = Notification {
|
let notif = Notification {
|
||||||
timeout: timeout,
|
timeout,
|
||||||
message: String::new(), // Not used in this special case
|
message: String::new(), // Not used in this special case
|
||||||
summary: "[Error]".to_owned(),
|
summary: "[Error]".to_owned(),
|
||||||
urgency: Urgency::High,
|
urgency: Urgency::High,
|
||||||
|
@ -62,7 +62,7 @@ pub mod err {
|
||||||
let mut n = RustNotification::new();
|
let mut n = RustNotification::new();
|
||||||
n.appname("imag");
|
n.appname("imag");
|
||||||
n.summary("[Error]");
|
n.summary("[Error]");
|
||||||
n.urgency(urgency.clone());
|
n.urgency(urgency);
|
||||||
n.body(e.description());
|
n.body(e.description());
|
||||||
try!(n.finalize().show().map(|_| ()).chain_err(|| NEK::Unknown));
|
try!(n.finalize().show().map(|_| ()).chain_err(|| NEK::Unknown));
|
||||||
|
|
||||||
|
|
|
@ -30,11 +30,7 @@ pub struct Date {
|
||||||
impl Date {
|
impl Date {
|
||||||
|
|
||||||
pub fn new(year: i32, month: u32, day: u32) -> Date {
|
pub fn new(year: i32, month: u32, day: u32) -> Date {
|
||||||
Date {
|
Date { year, month, day }
|
||||||
year: year,
|
|
||||||
month: month,
|
|
||||||
day: day,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn year(&self) -> i32 {
|
pub fn year(&self) -> i32 {
|
||||||
|
|
|
@ -31,10 +31,7 @@ pub struct DateTime {
|
||||||
impl DateTime {
|
impl DateTime {
|
||||||
|
|
||||||
pub fn new(date: Date, time: Time) -> DateTime {
|
pub fn new(date: Date, time: Time) -> DateTime {
|
||||||
DateTime {
|
DateTime { date, time }
|
||||||
date: date,
|
|
||||||
time: time
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn date(&self) -> &Date {
|
pub fn date(&self) -> &Date {
|
||||||
|
|
|
@ -30,11 +30,7 @@ pub struct Time {
|
||||||
impl Time {
|
impl Time {
|
||||||
|
|
||||||
pub fn new(hour: u32, minute: u32, second: u32) -> Time {
|
pub fn new(hour: u32, minute: u32, second: u32) -> Time {
|
||||||
Time {
|
Time { hour, minute, second }
|
||||||
hour: hour,
|
|
||||||
minute: minute,
|
|
||||||
second: second
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hour(&self) -> u32 {
|
pub fn hour(&self) -> u32 {
|
||||||
|
|
|
@ -23,27 +23,27 @@
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use boolinator::Boolinator;
|
use boolinator::Boolinator;
|
||||||
|
|
||||||
pub fn is_existing_path(s: String) -> Result<(), String> {
|
pub fn is_existing_path<A: AsRef<str>>(s: A) -> Result<(), String> {
|
||||||
PathBuf::from(s.clone()).exists().as_result((), format!("Not a File or Directory: {}", s))
|
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> {
|
pub fn is_file<A: AsRef<str>>(s: A) -> Result<(), String> {
|
||||||
PathBuf::from(s.clone()).is_file().as_result((), format!("Not a File: {}", s))
|
PathBuf::from(s.as_ref()).is_file().as_result((), format!("Not a File: {}", s.as_ref()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_directory(s: String) -> Result<(), String> {
|
pub fn is_directory<A: AsRef<str>>(s: A) -> Result<(), String> {
|
||||||
PathBuf::from(s.clone()).is_dir().as_result((), format!("Not a Directory: {}", s))
|
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;
|
use std::str::FromStr;
|
||||||
|
|
||||||
let i : Result<i64, _> = FromStr::from_str(&s);
|
let i : Result<i64, _> = FromStr::from_str(s.as_ref());
|
||||||
i.map(|_| ()).map_err(|_| format!("Not an integer: {}", s))
|
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;
|
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()))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ use chrono::NaiveDate;
|
||||||
use chrono::NaiveDateTime;
|
use chrono::NaiveDateTime;
|
||||||
use chrono::format::ParseError;
|
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 {
|
pub fn date_to_string(ndt: &NaiveDate) -> String {
|
||||||
ndt.format(NAIVE_DATE_STRING_FORMAT).to_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)
|
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 {
|
pub fn datetime_to_string(ndt: &NaiveDateTime) -> String {
|
||||||
ndt.format(NAIVE_DATETIME_STRING_FORMAT).to_string()
|
ndt.format(NAIVE_DATETIME_STRING_FORMAT).to_string()
|
||||||
|
|
|
@ -33,7 +33,7 @@ pub struct KeyValue<K, V> {
|
||||||
impl<K, V> KeyValue<K, V> {
|
impl<K, V> KeyValue<K, V> {
|
||||||
|
|
||||||
pub fn new(k: K, v: 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 {
|
pub fn key(&self) -> &K {
|
||||||
|
@ -75,7 +75,12 @@ impl IntoKeyValue<String, String> for String {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
R.captures(&self[..])
|
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| {
|
key.and_then(|k| {
|
||||||
|
|
|
@ -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>
|
-> Vec<C>
|
||||||
where
|
where
|
||||||
F: Fn(&A, B) -> C
|
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)]
|
#[cfg(test)]
|
||||||
|
@ -49,7 +49,7 @@ mod test {
|
||||||
fn test_variants_simple() {
|
fn test_variants_simple() {
|
||||||
let base = 1;
|
let base = 1;
|
||||||
let vars = vec![0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
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.len() == 11, format!("Length is {} instead of 11", res.len()));
|
||||||
assert!(res.iter().all(|i| *i > 0));
|
assert!(res.iter().all(|i| *i > 0));
|
||||||
|
@ -62,7 +62,7 @@ mod test {
|
||||||
|
|
||||||
let base = PathBuf::from("/");
|
let base = PathBuf::from("/");
|
||||||
let vars = vec!["foo", "bar", "baz"];
|
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();
|
let mut base = base.clone();
|
||||||
base.push(var);
|
base.push(var);
|
||||||
base
|
base
|
||||||
|
|
Loading…
Reference in a new issue