use crate::domain::asset::error::AssetError;
use std::fmt;
use std::str::FromStr;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct AssetSource(String);
impl AssetSource {
pub fn new(sql: impl Into<String>) -> Result<Self, AssetError> {
let sql = sql.into();
if sql.trim().is_empty() {
return Err(AssetError::EmptySource);
}
Ok(Self(sql))
}
pub fn as_str(&self) -> &str {
&self.0
}
}
impl fmt::Display for AssetSource {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(&self.0)
}
}
impl FromStr for AssetSource {
type Err = AssetError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::new(s)
}
}
impl AsRef<str> for AssetSource {
fn as_ref(&self) -> &str {
&self.0
}
}