From 47091a57408a6337a91096162832c4475bc9027c Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 6 Feb 2022 19:49:31 +0100 Subject: [PATCH] New parameter module --- src/command.rs | 7 ++-- src/error.rs | 3 +- src/main.rs | 36 +++++++++---------- src/{types.rs => numeric.rs} | 15 -------- src/parameter/mod.rs | 19 ++++++++++ .../range.rs} | 3 +- src/{ => parameter}/tokenize.rs | 0 7 files changed, 43 insertions(+), 40 deletions(-) rename src/{types.rs => numeric.rs} (76%) create mode 100644 src/parameter/mod.rs rename src/{parameter_range.rs => parameter/range.rs} (99%) rename src/{ => parameter}/tokenize.rs (100%) diff --git a/src/command.rs b/src/command.rs index e557dd0..dbfff4b 100644 --- a/src/command.rs +++ b/src/command.rs @@ -1,12 +1,13 @@ use std::collections::BTreeMap; use std::fmt; -use crate::{error::OptionsError, parameter_range::get_parameterized_commands}; +use crate::error::OptionsError; +use crate::parameter::range::get_parameterized_commands; use clap::ArgMatches; -use crate::tokenize::tokenize; -use crate::types::ParameterValue; +use crate::parameter::tokenize::tokenize; +use crate::parameter::ParameterValue; use anyhow::{bail, Result}; diff --git a/src/error.rs b/src/error.rs index 1588dc8..51958da 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,5 +1,4 @@ -use std::num; -use std::num::ParseIntError; +use std::num::{self, ParseIntError}; use rust_decimal::Error as DecimalError; use thiserror::Error; diff --git a/src/main.rs b/src/main.rs index 1bfb94d..b053170 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,24 +1,5 @@ use std::env; -use colored::*; - -pub mod app; -pub mod benchmark; -pub mod command; -pub mod error; -pub mod export; -pub mod min_max; -pub mod options; -pub mod outlier_detection; -pub mod output; -pub mod parameter_range; -pub mod relative_speed; -pub mod shell; -pub mod timer; -pub mod tokenize; -pub mod types; -pub mod units; - use app::get_arg_matches; use benchmark::result::BenchmarkResult; use benchmark::{mean_shell_spawning_time, run_benchmark}; @@ -27,6 +8,23 @@ use export::ExportManager; use options::{Options, OutputStyleOption}; use anyhow::{bail, Result}; +use colored::*; + +pub mod app; +pub mod benchmark; +pub mod command; +pub mod error; +pub mod export; +pub mod min_max; +pub mod numeric; +pub mod options; +pub mod outlier_detection; +pub mod output; +pub mod parameter; +pub mod relative_speed; +pub mod shell; +pub mod timer; +pub mod units; pub fn write_benchmark_comparison(results: &[BenchmarkResult]) { if results.len() < 2 { diff --git a/src/types.rs b/src/numeric.rs similarity index 76% rename from src/types.rs rename to src/numeric.rs index 1dc6863..1e7a517 100644 --- a/src/types.rs +++ b/src/numeric.rs @@ -46,18 +46,3 @@ impl TryFrom for usize { } } } - -#[derive(Debug, Clone, PartialEq, Eq)] -pub enum ParameterValue { - Text(String), - Numeric(NumericType), -} - -impl<'a> ToString for ParameterValue { - fn to_string(&self) -> String { - match self { - ParameterValue::Text(ref value) => value.clone(), - ParameterValue::Numeric(value) => value.to_string(), - } - } -} diff --git a/src/parameter/mod.rs b/src/parameter/mod.rs new file mode 100644 index 0000000..96095ec --- /dev/null +++ b/src/parameter/mod.rs @@ -0,0 +1,19 @@ +use crate::numeric::NumericType; + +pub mod range; +pub mod tokenize; + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum ParameterValue { + Text(String), + Numeric(NumericType), +} + +impl<'a> ToString for ParameterValue { + fn to_string(&self) -> String { + match self { + ParameterValue::Text(ref value) => value.clone(), + ParameterValue::Numeric(value) => value.to_string(), + } + } +} diff --git a/src/parameter_range.rs b/src/parameter/range.rs similarity index 99% rename from src/parameter_range.rs rename to src/parameter/range.rs index cc972ff..aed9870 100644 --- a/src/parameter_range.rs +++ b/src/parameter/range.rs @@ -5,9 +5,10 @@ use std::str::FromStr; use clap::Values; use rust_decimal::Decimal; +use super::ParameterValue; use crate::command::Command; use crate::error::ParameterScanError; -use crate::types::{NumericType, ParameterValue}; +use crate::numeric::NumericType; trait Numeric: Add diff --git a/src/tokenize.rs b/src/parameter/tokenize.rs similarity index 100% rename from src/tokenize.rs rename to src/parameter/tokenize.rs