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