#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ModelName(String);
impl ModelName {
pub fn new(name: impl Into<String>) -> crate::Result<Self> {
let name = name.into();
let trimmed = name.trim();
if trimmed.is_empty() {
return Err(Error::invalid_input(
"Model name cannot be empty or whitespace",
));
}
Ok(ModelName(name))
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn into_inner(self) -> String {
self.0
}
}
impl std::fmt::Display for ModelName {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct BaseUrl(String);
impl BaseUrl {
pub fn new(url: impl Into<String>) -> crate::Result<Self> {
let url = url.into();
let trimmed = url.trim();
if trimmed.is_empty() {
return Err(Error::invalid_input("base_url cannot be empty"));
}
if !trimmed.starts_with("http://") && !trimmed.starts_with("https://") {
return Err(Error::invalid_input(
"base_url must start with http:// or https://",
));
}
Ok(BaseUrl(url))
}
pub fn as_str(&self) -> &str {
&self.0
}
pub fn into_inner(self) -> String {
self.0
}
}
impl std::fmt::Display for BaseUrl {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Temperature(f32);
impl Temperature {
pub fn new(temp: f32) -> crate::Result<Self> {
if !(0.0..=2.0).contains(&temp) {
return Err(Error::invalid_input(
"temperature must be between 0.0 and 2.0",
));
}
Ok(Temperature(temp))
}
pub fn value(&self) -> f32 {
self.0
}
}
impl std::fmt::Display for Temperature {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}