|
|
|
@ -1,80 +1,130 @@
|
|
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
|
|
use crate::{HashablePrimitive, Primitive, Value};
|
|
|
|
|
use crate::{Float, HashablePrimitive, HashableValue, Primitive, Value};
|
|
|
|
|
|
|
|
|
|
pub trait RustyValue {
|
|
|
|
|
fn into_rusty_value(self) -> Value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for u8 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::U8(self)))
|
|
|
|
|
pub trait HashableRustyValue {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HashableRustyValue for usize {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::USize(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for i8 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::I8(self)))
|
|
|
|
|
impl HashableRustyValue for isize {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::ISize(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for u16 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::U16(self)))
|
|
|
|
|
impl HashableRustyValue for u8 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::U8(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for i16 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::I16(self)))
|
|
|
|
|
impl HashableRustyValue for i8 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::I8(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for u32 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::U32(self)))
|
|
|
|
|
impl HashableRustyValue for u16 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::U16(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for i32 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::I32(self)))
|
|
|
|
|
impl HashableRustyValue for i16 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::I16(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for u64 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::U64(self)))
|
|
|
|
|
impl HashableRustyValue for u32 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::U32(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for i64 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::I64(self)))
|
|
|
|
|
impl HashableRustyValue for i32 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::I32(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HashableRustyValue for u64 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::U64(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HashableRustyValue for i64 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::I64(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HashableRustyValue for u128 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::U128(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for u128 {
|
|
|
|
|
impl HashableRustyValue for i128 {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Integer(crate::Integer::I128(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HashableRustyValue for String {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::String(self))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl HashableRustyValue for bool {
|
|
|
|
|
fn into_hashable_rusty_value(self) -> HashableValue {
|
|
|
|
|
HashableValue::Primitive(HashablePrimitive::Bool(self))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for HashableValue {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::U128(self)))
|
|
|
|
|
match self {
|
|
|
|
|
HashableValue::Primitive(p) => match p {
|
|
|
|
|
HashablePrimitive::Integer(i) => Value::Primitive(Primitive::Integer(i)),
|
|
|
|
|
HashablePrimitive::String(s) => Value::Primitive(Primitive::String(s)),
|
|
|
|
|
HashablePrimitive::Char(c) => Value::Primitive(Primitive::Char(c)),
|
|
|
|
|
HashablePrimitive::Bool(b) => Value::Primitive(Primitive::Bool(b)),
|
|
|
|
|
},
|
|
|
|
|
HashableValue::List(l) => {
|
|
|
|
|
Value::List(l.into_iter().map(|v| v.into_rusty_value()).collect())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for i128 {
|
|
|
|
|
impl<H: HashableRustyValue> RustyValue for H {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Integer(crate::Integer::I128(self)))
|
|
|
|
|
self.into_hashable_rusty_value().into_rusty_value()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for String {
|
|
|
|
|
impl RustyValue for f32 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::String(self))
|
|
|
|
|
Value::Primitive(Primitive::Float(Float::F32(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl RustyValue for bool {
|
|
|
|
|
impl RustyValue for f64 {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
Value::Primitive(Primitive::Bool(self))
|
|
|
|
|
Value::Primitive(Primitive::Float(Float::F64(self)))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -89,11 +139,11 @@ impl<R: RustyValue> RustyValue for Vec<R> {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<R: RustyValue> RustyValue for HashMap<String, R> {
|
|
|
|
|
impl<R: RustyValue, H: HashableRustyValue> RustyValue for HashMap<H, R> {
|
|
|
|
|
fn into_rusty_value(self) -> Value {
|
|
|
|
|
let map = self
|
|
|
|
|
.into_iter()
|
|
|
|
|
.map(|(k, v)| (HashablePrimitive::String(k), v.into_rusty_value()))
|
|
|
|
|
.map(|(k, v)| (k.into_hashable_rusty_value(), v.into_rusty_value()))
|
|
|
|
|
.collect::<HashMap<_, _>>();
|
|
|
|
|
|
|
|
|
|
Value::Map(map)
|
|
|
|
|