From c5cf1106c3e802341578d1c9fb1b121b54e11742 Mon Sep 17 00:00:00 2001 From: Avril Date: Wed, 3 Mar 2021 17:07:25 +0000 Subject: [PATCH] added processing skel added fatal error handler --- shuffle3rs/Cargo.toml | 7 +++++-- shuffle3rs/src/main.rs | 22 ++++++++++++++++++++-- shuffle3rs/src/proc.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 shuffle3rs/src/proc.rs diff --git a/shuffle3rs/Cargo.toml b/shuffle3rs/Cargo.toml index 749db1d..8beee66 100644 --- a/shuffle3rs/Cargo.toml +++ b/shuffle3rs/Cargo.toml @@ -15,11 +15,14 @@ opt-level = 1 opt-level = 1 [features] -default = ["splash", "deferred-drop"] +default = ["splash", "deferred-drop", "threads"] # Print name and info when printing help info splash = [] +# Process multiple inputs concurrently +threads = [] + # Move large objects to a seperate thread to be dropped. deferred-drop = [] @@ -27,7 +30,7 @@ deferred-drop = [] cfg-if = "1.0.0" lazy_static = "1.4.0" rand = "0.8.3" -smallvec = "1.6.1" +smallvec = {version = "1.6.1", features=["union"]} [dev-dependencies] rand_chacha = "0.3.0" diff --git a/shuffle3rs/src/main.rs b/shuffle3rs/src/main.rs index 0c5da7c..db3f935 100644 --- a/shuffle3rs/src/main.rs +++ b/shuffle3rs/src/main.rs @@ -9,18 +9,36 @@ #[cfg(feature="deferred-drop")] mod defer_drop; mod shuffle; mod arg; +mod proc; use arg::Mode; +/// Handle a fatal error +/// +/// # Method +/// On `Err`, print the error message and then exit with error code provided +fn handle_err_fatal(op: Result, errcd: i32) -> T + where E: std::error::Error +{ + match op + { + Ok(v) => v, + Err(err) => { + eprintln!("Fatal error: {}", err); + std::process::exit(errcd) + } + } +} + fn main() { match arg::parse_args() { Ok(Mode::Help) => arg::usage(), Ok(Mode::ShuffleInPlace(file)) => { - todo!() + handle_err_fatal(proc::process_files_ip(file, proc::ModeKind::Shuffle), -1); }, Ok(Mode::UnshuffleInPlace(file)) => { - todo!() + handle_err_fatal(proc::process_files_ip(file, proc::ModeKind::Unshuffle), -1); }, Err(err) => { eprintln!("Error: {}", err); diff --git a/shuffle3rs/src/proc.rs b/shuffle3rs/src/proc.rs new file mode 100644 index 0000000..4100d0d --- /dev/null +++ b/shuffle3rs/src/proc.rs @@ -0,0 +1,30 @@ +//! Actual processing +use super::*; +use std::path::{Path, PathBuf}; +use std::io; + +/// What kind of operation are we doing? +#[derive(Debug, Clone, PartialEq, Eq, Hash, Copy)] +pub enum ModeKind +{ + Shuffle, + Unshuffle +} + +pub fn shuffle_file(file: impl AsRef) -> io::Result<()> +{ + todo!() +} + +pub fn unshuffle_file(file: impl AsRef) -> io::Result<()> +{ + todo!() +} + +/// Process these files in place with this mode +pub fn process_files_ip(files: I, mode: ModeKind) -> io::Result<()> +where I: IntoIterator +{ + + todo!() +}