more conversions for values

This commit is contained in:
Chris Cochrun 2024-11-20 12:14:34 -06:00
parent f630d138cb
commit b4a393cce7

View file

@ -109,6 +109,42 @@ impl From<Value> for String {
} }
} }
impl From<Value> for i32 {
fn from(value: Value) -> Self {
match value {
Value::Number(num) => num as i32,
_ => 0,
}
}
}
impl From<Value> for i64 {
fn from(value: Value) -> Self {
match value {
Value::Number(num) => num,
_ => 0,
}
}
}
impl From<&Value> for i32 {
fn from(value: &Value) -> Self {
match value {
Value::Number(num) => *num as i32,
_ => 0,
}
}
}
impl From<&Value> for i64 {
fn from(value: &Value) -> Self {
match value {
Value::Number(num) => *num,
_ => 0,
}
}
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct Symbol(pub String); pub struct Symbol(pub String);