use crate::haystack::val::Value;
#[derive(PartialEq, PartialOrd, Eq, Ord, Hash, Clone, Debug, Default)]
pub struct Uri {
pub value: String,
}
impl Uri {
pub fn make(val: &str) -> Self {
Uri { value: val.into() }
}
}
impl From<String> for Uri {
fn from(value: String) -> Self {
Uri { value }
}
}
impl From<&str> for Uri {
fn from(value: &str) -> Self {
Uri::from(value.to_owned())
}
}
impl From<Uri> for Value {
fn from(value: Uri) -> Self {
Value::Uri(value)
}
}
impl TryFrom<&Value> for Uri {
type Error = &'static str;
fn try_from(value: &Value) -> Result<Self, Self::Error> {
match value {
Value::Uri(v) => Ok(v.clone()),
_ => Err("Value is not an `Uri`"),
}
}
}