From 12b669d59191f4a30c0d4af1975ad7026a3f5187 Mon Sep 17 00:00:00 2001 From: Jacob Hinkle Date: Thu, 27 Oct 2022 15:23:52 -0400 Subject: [PATCH] Run cargo fmt --- src/db.rs | 29 ++++++++++++++++++----------- src/fs.rs | 6 +++++- src/main.rs | 17 ++++++++--------- src/program.rs | 13 +++++++++---- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/db.rs b/src/db.rs index 35199c7..af68cbb 100644 --- a/src/db.rs +++ b/src/db.rs @@ -13,9 +13,9 @@ use rusqlite::Connection; use rusqlite_migration::{Error as RMError, Migrations, SchemaVersion, M}; use uuid; -use std::collections::{HashSet}; +use std::collections::HashSet; use std::num::NonZeroUsize; // for describing schema versions -use std::path::{PathBuf}; +use std::path::PathBuf; static MIGRATIONS: Lazy> = Lazy::new(|| { Migrations::new(vec![M::up(include_str!( @@ -77,9 +77,7 @@ pub struct SchemaUpdateResult { pub updated: bool, } /// Ensure that the schema in conn is current. -pub fn ensure_schema( - conn: &mut Connection, -) -> Result { +pub fn ensure_schema(conn: &mut Connection) -> Result { let old_version = schema_version(conn)?; let current_version = unsafe { NonZeroUsize::new_unchecked(CURRENT_SCHEMA_VERSION) }; Ok(SchemaUpdateResult { @@ -122,16 +120,22 @@ pub enum FindDatasetError { NotImplemented, } impl From for FindDatasetError { - fn from(e: std::io::Error) -> FindDatasetError { FindDatasetError::PathError(e) } + fn from(e: std::io::Error) -> FindDatasetError { + FindDatasetError::PathError(e) + } } /// Given a collection of paths, find a common directory containing them. -/// +/// /// Returns `Ok(path)` if `path` is the only dataset found and it contains all given search paths. pub fn find_dataset_dir(paths: &[PathBuf]) -> Result { let mut ds_dirs: HashSet = HashSet::new(); - let first_path = paths.iter().next().ok_or(FindDatasetError::NoPathsProvided)?.canonicalize()?; + let first_path = paths + .iter() + .next() + .ok_or(FindDatasetError::NoPathsProvided)? + .canonicalize()?; log::debug!("First path is {:?}", first_path); let mut common_path = first_path.to_path_buf(); @@ -184,14 +188,17 @@ pub fn find_dataset_dir(paths: &[PathBuf]) -> Result if ds_dirs.len() == 0 { Err(FindDatasetError::NoDataset(common_path)) } else if ds_dirs.len() == 1 { - let d = ds_dirs.iter().next().expect("ds_dirs has exactly one value"); + let d = ds_dirs + .iter() + .next() + .expect("ds_dirs has exactly one value"); if some_not_in_ds { Err(FindDatasetError::SomeNotInDataset) } else { Ok(d.to_path_buf()) } - - } else { // ds_dirs.len() > 1 + } else { + // ds_dirs.len() > 1 Err(FindDatasetError::MultipleDatasets { datasets: ds_dirs.into_iter().collect(), some_paths_not_in_dataset: some_not_in_ds, diff --git a/src/fs.rs b/src/fs.rs index fa5c0aa..e2db9a8 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -9,6 +9,10 @@ pub enum RecordError { } pub fn record(path: &Path, message: &String) -> Result<(), RecordError> { - log::info!("Recording path {:?} with user-provided message \"{}\"", path, message); + log::info!( + "Recording path {:?} with user-provided message \"{}\"", + path, + message + ); Err(RecordError::NotImplemented) } diff --git a/src/main.rs b/src/main.rs index 5bb7724..768a567 100644 --- a/src/main.rs +++ b/src/main.rs @@ -63,8 +63,10 @@ fn main() { Err(nancy::db::FindDatasetError::NoDataset(path)) => { log::info!("No dataset at or above nearest ancestor path: {:?}", path); if !initialize { - log::error!("Refusing to initialize a new dataset at {path:?}. \ - Pass the -i or --initialize flag to request initialization."); + log::error!( + "Refusing to initialize a new dataset at {path:?}. \ + Pass the -i or --initialize flag to request initialization." + ); process::exit(1); } let dbpath = &path.join("nancy.db"); @@ -82,10 +84,7 @@ fn main() { c.pragma_update(None, "foreign_keys", &"ON").unwrap(); match nancy::db::init(&mut c) { Err(e) => { - log::error!( - "Encountered error in initializing schema: {:?}", - e - ); + log::error!("Encountered error in initializing schema: {:?}", e); process::exit(1); } Ok(dataset_uuid) => { @@ -109,11 +108,11 @@ fn main() { } } c - }, + } Err(e) => { log::error!("Could not determine dataset directory: {:?}", e); process::exit(1); - }, + } Ok(path) => { // existing log::info!("Found existing dataset at path: {:?}", path); @@ -142,7 +141,7 @@ fn main() { } } c - }, + } }; if let Err(e) = nancy::program::with_program(&mut conn, "RECORD", message, |prog| { diff --git a/src/program.rs b/src/program.rs index 17d2cfa..a3720fa 100644 --- a/src/program.rs +++ b/src/program.rs @@ -2,7 +2,7 @@ use log; use rusqlite::{Connection, Error as RSQLError, Transaction}; extern crate derive_more; use derive_more::From; -use uuid::{Uuid}; +use uuid::Uuid; use std::time::{Instant, SystemTime}; @@ -38,8 +38,8 @@ impl Program { } } pub fn perform_task(self: &Program, inputs: &[TaskInput], f: F) -> R - where - F: FnOnce(&Task) -> R + where + F: FnOnce(&Task) -> R, { let start = Instant::now(); let u = Uuid::new_v4(); @@ -79,7 +79,12 @@ pub fn with_program Result<(), E>>( let log_target = &format!("nancy.program ({})", name); - log::info!(target: log_target, "Preparing program {} ({})", name, message); + log::info!( + target: log_target, + "Preparing program {} ({})", + name, + message + ); // start transaction let txres = conn.transaction();