mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-11-03 01:21:25 +00:00
Use 'enum' to represent numeric/textual parameter values
This commit is contained in:
1 parent
4a5d08ddc2
commit
d7dc232e2f
4 files changed
+35
-15
No files matched your search
+18
-3
@@ -39,6 +39,21 @@ impl Into<NumericType> for Decimal {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
pub enum ParameterValue<'a> {
|
||||
Text(&'a str),
|
||||
Numeric(NumericType),
|
||||
}
|
||||
|
||||
impl<'a> ToString for ParameterValue<'a> {
|
||||
fn to_string(&self) -> String {
|
||||
match self {
|
||||
ParameterValue::Text(value) => value.to_string(),
|
||||
ParameterValue::Numeric(value) => value.to_string(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A command that should be benchmarked.
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Command<'a> {
|
||||
@@ -46,7 +61,7 @@ pub struct Command<'a> {
|
||||
expression: &'a str,
|
||||
|
||||
/// A possible parameter value.
|
||||
parameter: Option<(&'a str, String)>,
|
||||
parameter: Option<(&'a str, ParameterValue<'a>)>,
|
||||
}
|
||||
|
||||
impl<'a> Command<'a> {
|
||||
@@ -60,7 +75,7 @@ impl<'a> Command<'a> {
|
||||
pub fn new_parametrized(
|
||||
expression: &'a str,
|
||||
parameter: &'a str,
|
||||
value: String,
|
||||
value: ParameterValue<'a>,
|
||||
) -> Command<'a> {
|
||||
Command {
|
||||
expression,
|
||||
@@ -78,7 +93,7 @@ impl<'a> Command<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_parameter(&self) -> &Option<(&'a str, String)> {
|
||||
pub fn get_parameter(&self) -> &Option<(&'a str, ParameterValue<'a>)> {
|
||||
&self.parameter
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user