diff --git a/01.workspace/heave/src/imp/bool_to_value.rs b/01.workspace/heave/src/imp/bool_to_value.rs new file mode 100644 index 0000000..f902d9d --- /dev/null +++ b/01.workspace/heave/src/imp/bool_to_value.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl ToValue for bool { + fn to_value(self) -> Value { + Value::Bool(self) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/f64_to_value.rs b/01.workspace/heave/src/imp/f64_to_value.rs new file mode 100644 index 0000000..e9ea902 --- /dev/null +++ b/01.workspace/heave/src/imp/f64_to_value.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl ToValue for f64 { + fn to_value(self) -> Value { + Value::Real(self) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/i64_to_value.rs b/01.workspace/heave/src/imp/i64_to_value.rs new file mode 100644 index 0000000..1649290 --- /dev/null +++ b/01.workspace/heave/src/imp/i64_to_value.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl ToValue for i64 { + fn to_value(self) -> Value { + Value::SignedInt(self) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/mod.rs b/01.workspace/heave/src/imp/mod.rs index 8b13789..2a2fbc0 100644 --- a/01.workspace/heave/src/imp/mod.rs +++ b/01.workspace/heave/src/imp/mod.rs @@ -1 +1,5 @@ - +pub mod bool_to_value; +pub mod f64_to_value; +pub mod i64_to_value; +pub mod string_to_value; +pub mod u64_to_value; diff --git a/01.workspace/heave/src/imp/string_to_value.rs b/01.workspace/heave/src/imp/string_to_value.rs new file mode 100644 index 0000000..84e5ba6 --- /dev/null +++ b/01.workspace/heave/src/imp/string_to_value.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl ToValue for String { + fn to_value(self) -> Value { + Value::Text(self) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/u64_to_value.rs b/01.workspace/heave/src/imp/u64_to_value.rs new file mode 100644 index 0000000..e4a5bf3 --- /dev/null +++ b/01.workspace/heave/src/imp/u64_to_value.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl ToValue for u64 { + fn to_value(self) -> Value { + Value::UnsignedInt(self) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/lib.rs b/01.workspace/heave/src/lib.rs index d91f43c..37600ab 100644 --- a/01.workspace/heave/src/lib.rs +++ b/01.workspace/heave/src/lib.rs @@ -12,3 +12,4 @@ pub use crate::str::entity::O as Entity; pub use crate::str::value::E as Value; pub use crate::trt::from_eav::T as FromEAV; pub use crate::trt::to_eav::T as ToEAV; +pub use crate::trt::to_value::T as ToValue; diff --git a/01.workspace/heave/src/str/attribute.rs b/01.workspace/heave/src/str/attribute.rs index d7c9afd..702dfc1 100644 --- a/01.workspace/heave/src/str/attribute.rs +++ b/01.workspace/heave/src/str/attribute.rs @@ -7,10 +7,10 @@ pub struct O { } impl O { - pub fn new(id: &str, value: Value) -> Self { + pub fn new(id: &str, value: impl ToValue) -> Self { Self { id: String::from(id), - value, + value: value.to_value(), } } } diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index 13e3ff5..9eebb27 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -13,7 +13,7 @@ impl O { attributes: std::collections::HashMap::new(), } } - pub fn with_attribute(mut self, id: &str, value: Value) -> Self { + pub fn with_attribute(mut self, id: &str, value: impl ToValue) -> Self { let attribute = Attribute::new(id, value); self.attributes.insert(attribute.id.clone(), attribute); self @@ -25,7 +25,7 @@ impl O { Some(attribute) => Some(&attribute.value), } } - pub fn set(&mut self, id: &str, value: Value) -> Option { + pub fn set(&mut self, id: &str, value: impl ToValue) -> Option { let attribute = Attribute::new(id, value); let previous_attribute = self.attributes.insert(attribute.id.clone(), attribute); match previous_attribute { diff --git a/01.workspace/heave/src/trt/mod.rs b/01.workspace/heave/src/trt/mod.rs index 651c8e9..583b746 100644 --- a/01.workspace/heave/src/trt/mod.rs +++ b/01.workspace/heave/src/trt/mod.rs @@ -1,2 +1,3 @@ pub mod from_eav; pub mod to_eav; +pub mod to_value; diff --git a/01.workspace/heave/src/trt/to_value.rs b/01.workspace/heave/src/trt/to_value.rs new file mode 100644 index 0000000..e7521a3 --- /dev/null +++ b/01.workspace/heave/src/trt/to_value.rs @@ -0,0 +1,8 @@ +use crate::*; + +pub trait T { + fn to_value(self) -> Value; +} + +// #[cfg(test)] +// mod unit_tests {}