diff options
author | David Peter <mail@david-peter.de> | 2022-02-06 19:54:59 +0100 |
---|---|---|
committer | David Peter <sharkdp@users.noreply.github.com> | 2022-02-06 20:19:50 +0100 |
commit | 999e7c4566f4a60df9509999d3b1ffe7df7571de (patch) | |
tree | 784a2ab4979fb5548f71fdcd27faa90bbfcef72a | |
parent | 47091a57408a6337a91096162832c4475bc9027c (diff) |
Move more modules around
-rw-r--r-- | src/benchmark/mod.rs | 1 | ||||
-rw-r--r-- | src/benchmark/relative_speed.rs (renamed from src/relative_speed.rs) | 2 | ||||
-rw-r--r-- | src/export/asciidoc.rs | 2 | ||||
-rw-r--r-- | src/export/markdown.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 5 | ||||
-rw-r--r-- | src/number.rs | 48 | ||||
-rw-r--r-- | src/numeric.rs | 48 | ||||
-rw-r--r-- | src/parameter/mod.rs | 4 | ||||
-rw-r--r-- | src/parameter/range.rs | 6 |
9 files changed, 59 insertions, 59 deletions
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 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<i32> for Number { + fn from(x: i32) -> Number { + Number::Int(x) + } +} + +impl From<Decimal> for Number { + fn from(x: Decimal) -> Number { + Number::Decimal(x) + } +} + +impl TryFrom<Number> for usize { + type Error = (); + + fn try_from(numeric: Number) -> Result<Self, Self::Error> { + 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<i32> for NumericType { - fn from(x: i32) -> NumericType { - NumericType::Int(x) - } -} - -impl From<Decimal> for NumericType { - fn from(x: Decimal) -> NumericType { - NumericType::Decimal(x) - } -} - -impl TryFrom<NumericType> for usize { - type Error = (); - - fn try_from(numeric: NumericType) -> Result<Self, Self::Error> { - 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<Output = Self> @@ -19,7 +19,7 @@ trait Numeric: + Copy + Clone + From<i32> - + Into<NumericType> + + Into<Number> { } impl< @@ -31,7 +31,7 @@ impl< + Copy + Clone + From<i32> - + Into<NumericType>, + + Into<Number>, > Numeric for T { } |