From 999e7c4566f4a60df9509999d3b1ffe7df7571de Mon Sep 17 00:00:00 2001 From: David Peter Date: Sun, 6 Feb 2022 19:54:59 +0100 Subject: [PATCH] Move more modules around --- src/benchmark/mod.rs | 1 + src/{ => benchmark}/relative_speed.rs | 2 +- src/export/asciidoc.rs | 2 +- src/export/markdown.rs | 2 +- src/main.rs | 5 ++- src/number.rs | 48 +++++++++++++++++++++++++++ src/numeric.rs | 48 --------------------------- src/parameter/mod.rs | 4 +-- src/parameter/range.rs | 6 ++-- 9 files changed, 59 insertions(+), 59 deletions(-) rename src/{ => benchmark}/relative_speed.rs (98%) create mode 100644 src/number.rs delete mode 100644 src/numeric.rs diff --git a/src/benchmark/mod.rs b/src/benchmark/mod.rs index c5396a2..ae1403a 100644 --- a/src/benchmark/mod.rs +++ b/src/benchmark/mod.rs @@ -1,3 +1,4 @@ +pub mod relative_speed; pub mod result; use std::cmp; diff --git a/src/relative_speed.rs b/src/benchmark/relative_speed.rs similarity index 98% rename from src/relative_speed.rs rename to src/benchmark/relative_speed.rs index 7bc7353..21732af 100644 --- a/src/relative_speed.rs +++ b/src/benchmark/relative_speed.rs @@ -1,6 +1,6 @@ use std::cmp::Ordering; -use crate::benchmark::result::BenchmarkResult; +use super::result::BenchmarkResult; use crate::units::Scalar; #[derive(Debug)] diff --git a/src/export/asciidoc.rs b/src/export/asciidoc.rs index c9a77f6..bfa056f 100644 --- a/src/export/asciidoc.rs +++ b/src/export/asciidoc.rs @@ -1,6 +1,6 @@ +use crate::benchmark::relative_speed::{self, BenchmarkResultWithRelativeSpeed}; use crate::benchmark::result::BenchmarkResult; use crate::output::format::format_duration_value; -use crate::relative_speed::{self, BenchmarkResultWithRelativeSpeed}; use crate::units::Unit; use super::Exporter; diff --git a/src/export/markdown.rs b/src/export/markdown.rs index 5b3808b..65f1652 100644 --- a/src/export/markdown.rs +++ b/src/export/markdown.rs @@ -1,7 +1,7 @@ use super::Exporter; +use crate::benchmark::relative_speed::{self, BenchmarkResultWithRelativeSpeed}; use crate::benchmark::result::BenchmarkResult; use crate::output::format::format_duration_value; -use crate::relative_speed::{self, BenchmarkResultWithRelativeSpeed}; use crate::units::Unit; use anyhow::{anyhow, Result}; diff --git a/src/main.rs b/src/main.rs index b053170..7f5def2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,7 +2,7 @@ use std::env; use app::get_arg_matches; use benchmark::result::BenchmarkResult; -use benchmark::{mean_shell_spawning_time, run_benchmark}; +use benchmark::{mean_shell_spawning_time, relative_speed, run_benchmark}; use command::{build_commands, Command}; use export::ExportManager; use options::{Options, OutputStyleOption}; @@ -16,12 +16,11 @@ pub mod command; pub mod error; pub mod export; pub mod min_max; -pub mod numeric; +pub mod number; 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; diff --git a/src/number.rs b/src/number.rs new file mode 100644 index 0000000..124a04c --- /dev/null +++ b/src/number.rs @@ -0,0 +1,48 @@ +use std::convert::TryFrom; +use std::fmt; + +use rust_decimal::prelude::ToPrimitive; +use rust_decimal::Decimal; +use serde::Serialize; + +#[derive(Debug, Clone, Serialize, Copy, PartialEq, Eq)] +#[serde(untagged)] +pub enum Number { + Int(i32), + Decimal(Decimal), +} + +impl fmt::Display for Number { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match *self { + Number::Int(i) => fmt::Display::fmt(&i, f), + Number::Decimal(i) => fmt::Display::fmt(&i, f), + } + } +} + +impl From for Number { + fn from(x: i32) -> Number { + Number::Int(x) + } +} + +impl From for Number { + fn from(x: Decimal) -> Number { + Number::Decimal(x) + } +} + +impl TryFrom for usize { + type Error = (); + + fn try_from(numeric: Number) -> Result { + match numeric { + Number::Int(i) => usize::try_from(i).map_err(|_| ()), + Number::Decimal(d) => match d.to_u64() { + Some(u) => usize::try_from(u).map_err(|_| ()), + None => Err(()), + }, + } + } +} diff --git a/src/numeric.rs b/src/numeric.rs deleted file mode 100644 index 1e7a517..0000000 --- a/src/numeric.rs +++ /dev/null @@ -1,48 +0,0 @@ -use std::convert::TryFrom; -use std::fmt; - -use rust_decimal::prelude::ToPrimitive; -use rust_decimal::Decimal; -use serde::Serialize; - -#[derive(Debug, Clone, Serialize, Copy, PartialEq, Eq)] -#[serde(untagged)] -pub enum NumericType { - Int(i32), - Decimal(Decimal), -} - -impl fmt::Display for NumericType { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match *self { - NumericType::Int(i) => fmt::Display::fmt(&i, f), - NumericType::Decimal(i) => fmt::Display::fmt(&i, f), - } - } -} - -impl From for NumericType { - fn from(x: i32) -> NumericType { - NumericType::Int(x) - } -} - -impl From for NumericType { - fn from(x: Decimal) -> NumericType { - NumericType::Decimal(x) - } -} - -impl TryFrom for usize { - type Error = (); - - fn try_from(numeric: NumericType) -> Result { - match numeric { - NumericType::Int(i) => usize::try_from(i).map_err(|_| ()), - NumericType::Decimal(d) => match d.to_u64() { - Some(u) => usize::try_from(u).map_err(|_| ()), - None => Err(()), - }, - } - } -} diff --git a/src/parameter/mod.rs b/src/parameter/mod.rs index 96095ec..dfccc23 100644 --- a/src/parameter/mod.rs +++ b/src/parameter/mod.rs @@ -1,4 +1,4 @@ -use crate::numeric::NumericType; +use crate::number::Number; pub mod range; pub mod tokenize; @@ -6,7 +6,7 @@ pub mod tokenize; #[derive(Debug, Clone, PartialEq, Eq)] pub enum ParameterValue { Text(String), - Numeric(NumericType), + Numeric(Number), } impl<'a> ToString for ParameterValue { diff --git a/src/parameter/range.rs b/src/parameter/range.rs index aed9870..172a394 100644 --- a/src/parameter/range.rs +++ b/src/parameter/range.rs @@ -8,7 +8,7 @@ use rust_decimal::Decimal; use super::ParameterValue; use crate::command::Command; use crate::error::ParameterScanError; -use crate::numeric::NumericType; +use crate::number::Number; trait Numeric: Add @@ -19,7 +19,7 @@ trait Numeric: + Copy + Clone + From - + Into + + Into { } impl< @@ -31,7 +31,7 @@ impl< + Copy + Clone + From - + Into, + + Into, > Numeric for T { }