added processing skel

added fatal error handler
rust
Avril 4 years ago
parent 204f511075
commit c5cf1106c3
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -15,11 +15,14 @@ opt-level = 1
opt-level = 1 opt-level = 1
[features] [features]
default = ["splash", "deferred-drop"] default = ["splash", "deferred-drop", "threads"]
# Print name and info when printing help info # Print name and info when printing help info
splash = [] splash = []
# Process multiple inputs concurrently
threads = []
# Move large objects to a seperate thread to be dropped. # Move large objects to a seperate thread to be dropped.
deferred-drop = [] deferred-drop = []
@ -27,7 +30,7 @@ deferred-drop = []
cfg-if = "1.0.0" cfg-if = "1.0.0"
lazy_static = "1.4.0" lazy_static = "1.4.0"
rand = "0.8.3" rand = "0.8.3"
smallvec = "1.6.1" smallvec = {version = "1.6.1", features=["union"]}
[dev-dependencies] [dev-dependencies]
rand_chacha = "0.3.0" rand_chacha = "0.3.0"

@ -9,18 +9,36 @@
#[cfg(feature="deferred-drop")] mod defer_drop; #[cfg(feature="deferred-drop")] mod defer_drop;
mod shuffle; mod shuffle;
mod arg; mod arg;
mod proc;
use arg::Mode; 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<T, E>(op: Result<T, E>, 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() { fn main() {
match arg::parse_args() match arg::parse_args()
{ {
Ok(Mode::Help) => arg::usage(), Ok(Mode::Help) => arg::usage(),
Ok(Mode::ShuffleInPlace(file)) => { Ok(Mode::ShuffleInPlace(file)) => {
todo!() handle_err_fatal(proc::process_files_ip(file, proc::ModeKind::Shuffle), -1);
}, },
Ok(Mode::UnshuffleInPlace(file)) => { Ok(Mode::UnshuffleInPlace(file)) => {
todo!() handle_err_fatal(proc::process_files_ip(file, proc::ModeKind::Unshuffle), -1);
}, },
Err(err) => { Err(err) => {
eprintln!("Error: {}", err); eprintln!("Error: {}", err);

@ -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<Path>) -> io::Result<()>
{
todo!()
}
pub fn unshuffle_file(file: impl AsRef<Path>) -> io::Result<()>
{
todo!()
}
/// Process these files in place with this mode
pub fn process_files_ip<I>(files: I, mode: ModeKind) -> io::Result<()>
where I: IntoIterator<Item = PathBuf>
{
todo!()
}
Loading…
Cancel
Save