1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
use std::error::Error;
use clap::{Arg, App};

#[macro_use]
extern crate clap;

// deleteme
#[macro_use]
extern crate ndarray;

mod array_implementation;

pub struct Config {
    pub rows: usize,
    pub cols: usize,
}

impl Config {
    pub fn new() -> Result<Config, String> {
        let matches = App::new("Convolician")
            .version("1.0")
            .author(crate_authors!())
            .about("Calculates the central difference of a 2d unsigned char matrix")
            .arg(Arg::with_name("rows")
                .required(true)
                .help("Number of rows in the random matrix"))
            .arg(Arg::with_name("cols")
                .required(true)
                .help("Number of columns in the random matrix"))
            .get_matches();

        let rows = value_t!(matches, "rows", usize).map_err(|e| { e.message })?;
        let cols = value_t!(matches, "cols", usize).map_err(|e| { e.message })?;

        if rows < 1 || cols < 1 {
            return Err(String::from("<rows> and <cols> arguments must be positive integers"));
        }

        println!("Convolving a random {}x{} matrix...", rows, cols);

        Ok(Config { rows, cols })
    }
}

pub fn run(config: Config) -> Result<(), Box<dyn Error>> {
    array_implementation::run(config.rows, config.cols)
}