#[derive(Clone, Debug)]
pub enum RullstValue {
String(String),
Int(i32),
Float(f64),
Bool(bool),
}
impl From<&str> for RullstValue {
fn from(s: &str) -> Self {
RullstValue::String(s.to_string())
}
}
impl From<String> for RullstValue {
fn from(s: String) -> Self {
RullstValue::String(s)
}
}
impl From<i32> for RullstValue {
fn from(i: i32) -> Self {
RullstValue::Int(i)
}
}
impl From<f64> for RullstValue {
fn from(f: f64) -> Self {
RullstValue::Float(f)
}
}
impl From<bool> for RullstValue {
fn from(b: bool) -> Self {
RullstValue::Bool(b)
}
}
impl TryFrom<RullstValue> for String {
type Error = &'static str;
fn try_from(val: RullstValue) -> Result<Self, Self::Error> {
match val {
RullstValue::String(s) => Ok(s),
_ => Err("Not a string"),
}
}
}
impl TryFrom<RullstValue> for i32 {
type Error = &'static str;
fn try_from(val: RullstValue) -> Result<Self, Self::Error> {
match val {
RullstValue::Int(i) => Ok(i),
_ => Err("Not an i32"),
}
}
}
impl TryFrom<RullstValue> for f64 {
type Error = &'static str;
fn try_from(val: RullstValue) -> Result<Self, Self::Error> {
match val {
RullstValue::Float(f) => Ok(f),
_ => Err("Not an f64"),
}
}
}
impl TryFrom<RullstValue> for bool {
type Error = &'static str;
fn try_from(val: RullstValue) -> Result<Self, Self::Error> {
match val {
RullstValue::Bool(b) => Ok(b),
_ => Err("Not a bool"),
}
}
}