#[derive(Debug, Clone, PartialEq, Eq, Hash, serde::Serialize, serde::Deserialize)]
pub struct ModelId(pub String);
impl ModelId {
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<&str> for ModelId {
fn from(s: &str) -> Self {
Self(s.to_string())
}
}
impl From<String> for ModelId {
fn from(s: String) -> Self {
Self(s)
}
}
impl std::fmt::Display for ModelId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.0)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn round_trips_through_str_and_string() {
assert_eq!(
ModelId::from("claude-sonnet-4-6").as_str(),
"claude-sonnet-4-6"
);
assert_eq!(ModelId::from("x".to_string()).to_string(), "x");
}
#[test]
fn equality_is_by_value() {
assert_eq!(ModelId::from("a"), ModelId::from("a"));
assert_ne!(ModelId::from("a"), ModelId::from("b"));
}
}