Skip to content

Commit

Permalink
Moving FromStr for SamplerType to cli module
Browse files Browse the repository at this point in the history
  • Loading branch information
bazhenov committed Dec 15, 2023
1 parent 4b360c4 commit fbd4cf1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
13 changes: 13 additions & 0 deletions tango-bench/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use std::{
};

pub type Result<T> = anyhow::Result<T>;
pub type StdResult<T, E> = std::result::Result<T, E>;

#[derive(Parser, Debug)]
enum BenchmarkMode {
Expand Down Expand Up @@ -83,6 +84,18 @@ struct Opts {
coloring_mode: String,
}

impl FromStr for SamplerType {
type Err = Error;

fn from_str(s: &str) -> StdResult<Self, Self::Err> {
match s {
"flat" => Ok(SamplerType::Flat),
"linear" => Ok(SamplerType::Linear),
_ => Err(Error::UnknownSamplerType),
}
}
}

/// Definition of the flags required to comply with `cargo bench` calling conventions.
#[derive(Parser, Debug, Clone)]
struct CargoBenchFlags {
Expand Down
14 changes: 1 addition & 13 deletions tango-bench/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::{
io,
ops::{Add, Div, RangeInclusive},
rc::Rc,
str::{FromStr, Utf8Error},
str::Utf8Error,
};
use thiserror::Error;
use timer::{ActiveTimer, Timer};
Expand Down Expand Up @@ -460,18 +460,6 @@ pub enum SamplerType {
Linear,
}

impl FromStr for SamplerType {
type Err = Error;

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"flat" => Ok(SamplerType::Flat),
"linear" => Ok(SamplerType::Linear),
_ => Err(Error::UnknownSamplerType),
}
}
}

pub const DEFAULT_SETTINGS: MeasurementSettings = MeasurementSettings {
filter_outliers: false,
samples_per_haystack: 1,
Expand Down

0 comments on commit fbd4cf1

Please sign in to comment.