Derive Default for InMemoryFileAbstraction, remove constructor

This commit is contained in:
Matthias Beyer 2018-04-24 21:32:22 +02:00
parent 6a34e7a8fd
commit ea80a5a09b
11 changed files with 15 additions and 21 deletions

View file

@ -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)
}; };

View file

@ -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
} }

View file

@ -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");

View file

@ -1176,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()
} }
@ -1361,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()
@ -1377,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())

View file

@ -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()
} }

View file

@ -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()
} }

View file

@ -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()
} }

View file

@ -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()
} }

View file

@ -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()
} }

View file

@ -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()
} }

View file

@ -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()
} }