Move more modules around

This commit is contained in:
David Peter authored and David Peter committed 2022-02-06 20:19:50 +01:00
1 parent 47091a5740
commit 999e7c4566
9 files changed
+59 -59

No files matched your search

+1
View File
@@ -1,3 +1,4 @@
pub mod relative_speed;
pub mod result;
use std::cmp;
@@ -1,6 +1,6 @@
use std::cmp::Ordering;
use crate::benchmark::result::BenchmarkResult;
use super::result::BenchmarkResult;
use crate::units::Scalar;
#[derive(Debug)]
+1 -1
View File
@@ -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;
+1 -1
View File
@@ -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};
+2 -3
View File
@@ -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;
+48
View File
@@ -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(()),
},
}
}
}
-48
View File
@@ -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(()),
},
}
}
}
+2 -2
View File
@@ -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 {
+3 -3
View File
@@ -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
{
}