1#![warn(missing_debug_implementations, missing_docs)]
6use std::str::FromStr;
7
8#[derive(Debug, PartialEq, Eq, Clone, Copy)]
10pub enum Metric {
11 L2,
13
14 Cosine,
17}
18
19#[derive(thiserror::Error, Debug)]
20pub enum ParseMetricError {
21 #[error("Invalid format for Metric: {0}")]
22 InvalidFormat(String),
23}
24
25impl FromStr for Metric {
26 type Err = ParseMetricError;
27
28 fn from_str(s: &str) -> Result<Self, Self::Err> {
29 match s.to_lowercase().as_str() {
30 "l2" => Ok(Metric::L2),
31 "cosine" => Ok(Metric::Cosine),
32 _ => Err(ParseMetricError::InvalidFormat(String::from(s))),
33 }
34 }
35}