| 1 |
|
| 2 |
|
| 3 |
use crate::{Error, Metric, MetricType, Result}; |
| 4 |
use alloc::borrow::ToOwned; |
| 5 |
use core::{fmt, str::FromStr}; |
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
#[derive(Copy, Clone, Debug, Eq, PartialEq, PartialOrd, Ord)] |
| 19 |
pub enum UserInteraction { |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
Required, |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
None, |
| 32 |
} |
| 33 |
|
| 34 |
impl Metric for UserInteraction { |
| 35 |
const TYPE: MetricType = MetricType::UI; |
| 36 |
|
| 37 |
fn score(self) -> f64 { |
| 38 |
match self { |
| 39 |
UserInteraction::Required => 0.62, |
| 40 |
UserInteraction::None => 0.85, |
| 41 |
} |
| 42 |
} |
| 43 |
|
| 44 |
fn as_str(self) -> &'static str { |
| 45 |
match self { |
| 46 |
UserInteraction::Required => "R", |
| 47 |
UserInteraction::None => "N", |
| 48 |
} |
| 49 |
} |
| 50 |
} |
| 51 |
|
| 52 |
impl fmt::Display for UserInteraction { |
| 53 |
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { |
| 54 |
write!(f, "{}:{}", Self::name(), self.as_str()) |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
impl FromStr for UserInteraction { |
| 59 |
type Err = Error; |
| 60 |
|
| 61 |
fn from_str(s: &str) -> Result<Self> { |
| 62 |
match s { |
| 63 |
"R" => Ok(UserInteraction::Required), |
| 64 |
"N" => Ok(UserInteraction::None), |
| 65 |
_ => Err(Error::InvalidMetric { |
| 66 |
metric_type: Self::TYPE, |
| 67 |
value: s.to_owned(), |
| 68 |
}), |
| 69 |
} |
| 70 |
} |
| 71 |
} |