use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum Profile {
Mobile,
Balanced,
Custom,
}
impl Profile {
pub const fn embedding_dim(self) -> usize {
match self {
Profile::Mobile => 512, Profile::Balanced => 256, Profile::Custom => 0,
}
}
pub const fn default_threshold(self) -> f32 {
match self {
Profile::Mobile => 0.55,
Profile::Balanced => 0.45,
Profile::Custom => 0.5,
}
}
pub const fn manifest_id(self) -> &'static str {
match self {
Profile::Mobile => "mobile",
Profile::Balanced => "balanced",
Profile::Custom => "custom",
}
}
}
impl std::str::FromStr for Profile {
type Err = ProfileParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"mobile" => Ok(Profile::Mobile),
"balanced" => Ok(Profile::Balanced),
"custom" => Ok(Profile::Custom),
other => Err(ProfileParseError(other.to_owned())),
}
}
}
#[derive(Debug, Clone)]
pub struct ProfileParseError(pub String);
impl std::fmt::Display for ProfileParseError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"unknown profile '{}': expected mobile|balanced|custom",
self.0
)
}
}
impl std::error::Error for ProfileParseError {}