From af860bdb220c7033e0755228ced1e528d0d96d23 Mon Sep 17 00:00:00 2001 From: davidemazzocchi Date: Tue, 30 Sep 2025 07:04:26 +0200 Subject: [PATCH] refactor: remove trait to_value in favor of Into --- 01.workspace/heave/src/imp/bool_to_value.rs | 10 --------- 01.workspace/heave/src/imp/entity_to_value.rs | 10 --------- 01.workspace/heave/src/imp/f64_to_value.rs | 10 --------- 01.workspace/heave/src/imp/i64_to_value.rs | 10 --------- 01.workspace/heave/src/imp/mod.rs | 21 ++++++++++++------- 01.workspace/heave/src/imp/str_to_value.rs | 10 --------- 01.workspace/heave/src/imp/string_to_value.rs | 10 --------- 01.workspace/heave/src/imp/u64_to_value.rs | 10 --------- 01.workspace/heave/src/imp/value_from_bool.rs | 10 +++++++++ .../heave/src/imp/value_from_entity.rs | 10 +++++++++ 01.workspace/heave/src/imp/value_from_f64.rs | 10 +++++++++ 01.workspace/heave/src/imp/value_from_i64.rs | 10 +++++++++ 01.workspace/heave/src/imp/value_from_str.rs | 10 +++++++++ .../heave/src/imp/value_from_string.rs | 10 +++++++++ 01.workspace/heave/src/imp/value_from_u64.rs | 10 +++++++++ 01.workspace/heave/src/lib.rs | 2 +- 01.workspace/heave/src/str/attribute.rs | 4 ++-- 01.workspace/heave/src/str/entity.rs | 4 ++-- 01.workspace/heave/src/trt/mod.rs | 1 - 01.workspace/heave/src/trt/to_value.rs | 8 ------- 20 files changed, 89 insertions(+), 91 deletions(-) delete mode 100644 01.workspace/heave/src/imp/bool_to_value.rs delete mode 100644 01.workspace/heave/src/imp/entity_to_value.rs delete mode 100644 01.workspace/heave/src/imp/f64_to_value.rs delete mode 100644 01.workspace/heave/src/imp/i64_to_value.rs delete mode 100644 01.workspace/heave/src/imp/str_to_value.rs delete mode 100644 01.workspace/heave/src/imp/string_to_value.rs delete mode 100644 01.workspace/heave/src/imp/u64_to_value.rs create mode 100644 01.workspace/heave/src/imp/value_from_bool.rs create mode 100644 01.workspace/heave/src/imp/value_from_entity.rs create mode 100644 01.workspace/heave/src/imp/value_from_f64.rs create mode 100644 01.workspace/heave/src/imp/value_from_i64.rs create mode 100644 01.workspace/heave/src/imp/value_from_str.rs create mode 100644 01.workspace/heave/src/imp/value_from_string.rs create mode 100644 01.workspace/heave/src/imp/value_from_u64.rs delete mode 100644 01.workspace/heave/src/trt/to_value.rs diff --git a/01.workspace/heave/src/imp/bool_to_value.rs b/01.workspace/heave/src/imp/bool_to_value.rs deleted file mode 100644 index f902d9d..0000000 --- a/01.workspace/heave/src/imp/bool_to_value.rs +++ /dev/null @@ -1,10 +0,0 @@ -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/entity_to_value.rs b/01.workspace/heave/src/imp/entity_to_value.rs deleted file mode 100644 index e9c6a0c..0000000 --- a/01.workspace/heave/src/imp/entity_to_value.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::*; - -impl ToValue for Entity { - fn to_value(self) -> Value { - self.id.to_value() - } -} - -// #[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 deleted file mode 100644 index e9ea902..0000000 --- a/01.workspace/heave/src/imp/f64_to_value.rs +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 1649290..0000000 --- a/01.workspace/heave/src/imp/i64_to_value.rs +++ /dev/null @@ -1,10 +0,0 @@ -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 7796546..119ec13 100644 --- a/01.workspace/heave/src/imp/mod.rs +++ b/01.workspace/heave/src/imp/mod.rs @@ -1,13 +1,20 @@ pub mod bool_from_value; -pub mod bool_to_value; +// pub mod bool_to_value; pub mod entity_from_value; -pub mod entity_to_value; +// pub mod entity_to_value; pub mod f64_from_value; -pub mod f64_to_value; +// pub mod f64_to_value; pub mod i64_from_value; -pub mod i64_to_value; -pub mod str_to_value; +// pub mod i64_to_value; +// pub mod str_to_value; pub mod string_from_value; -pub mod string_to_value; +// pub mod string_to_value; pub mod u64_from_value; -pub mod u64_to_value; +// pub mod u64_to_value; +pub mod value_from_str; +pub mod value_from_string; +pub mod value_from_u64; +pub mod value_from_f64; +pub mod value_from_bool; +pub mod value_from_entity; +pub mod value_from_i64; diff --git a/01.workspace/heave/src/imp/str_to_value.rs b/01.workspace/heave/src/imp/str_to_value.rs deleted file mode 100644 index 7fa4221..0000000 --- a/01.workspace/heave/src/imp/str_to_value.rs +++ /dev/null @@ -1,10 +0,0 @@ -use crate::*; - -impl ToValue for &str { - fn to_value(self) -> Value { - Value::Text(String::from(self)) - } -} - -// #[cfg(test)] -// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/string_to_value.rs b/01.workspace/heave/src/imp/string_to_value.rs deleted file mode 100644 index 84e5ba6..0000000 --- a/01.workspace/heave/src/imp/string_to_value.rs +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index e4a5bf3..0000000 --- a/01.workspace/heave/src/imp/u64_to_value.rs +++ /dev/null @@ -1,10 +0,0 @@ -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/imp/value_from_bool.rs b/01.workspace/heave/src/imp/value_from_bool.rs new file mode 100644 index 0000000..890ed5d --- /dev/null +++ b/01.workspace/heave/src/imp/value_from_bool.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl From for Value { + fn from(value: bool) -> Self { + Self::Bool(value) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/value_from_entity.rs b/01.workspace/heave/src/imp/value_from_entity.rs new file mode 100644 index 0000000..67e9402 --- /dev/null +++ b/01.workspace/heave/src/imp/value_from_entity.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl From for Value { + fn from(value: Entity) -> Self { + Self::Text(value.id) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/value_from_f64.rs b/01.workspace/heave/src/imp/value_from_f64.rs new file mode 100644 index 0000000..ad6e02f --- /dev/null +++ b/01.workspace/heave/src/imp/value_from_f64.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl From for Value { + fn from(value: f64) -> Self { + Self::Real(value) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/value_from_i64.rs b/01.workspace/heave/src/imp/value_from_i64.rs new file mode 100644 index 0000000..b8547ca --- /dev/null +++ b/01.workspace/heave/src/imp/value_from_i64.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl From for Value { + fn from(value: i64) -> Self { + Self::SignedInt(value) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/value_from_str.rs b/01.workspace/heave/src/imp/value_from_str.rs new file mode 100644 index 0000000..6498818 --- /dev/null +++ b/01.workspace/heave/src/imp/value_from_str.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl From<&str> for Value { + fn from(value: &str) -> Self { + Self::Text(String::from(value)) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/value_from_string.rs b/01.workspace/heave/src/imp/value_from_string.rs new file mode 100644 index 0000000..7f6f835 --- /dev/null +++ b/01.workspace/heave/src/imp/value_from_string.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl From for Value { + fn from(value: String) -> Self { + Self::Text(value) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/imp/value_from_u64.rs b/01.workspace/heave/src/imp/value_from_u64.rs new file mode 100644 index 0000000..9f22216 --- /dev/null +++ b/01.workspace/heave/src/imp/value_from_u64.rs @@ -0,0 +1,10 @@ +use crate::*; + +impl From for Value { + fn from(value: u64) -> Self { + Self::UnsignedInt(value) + } +} + +// #[cfg(test)] +// mod unit_tests { use super::*; } diff --git a/01.workspace/heave/src/lib.rs b/01.workspace/heave/src/lib.rs index 644e03f..940a7a6 100644 --- a/01.workspace/heave/src/lib.rs +++ b/01.workspace/heave/src/lib.rs @@ -14,7 +14,7 @@ pub use crate::str::value::E as Value; pub use crate::trt::eav::T as EAV; 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; +// pub use crate::trt::to_value::T as ToValue; mod sqlite { pub mod init { diff --git a/01.workspace/heave/src/str/attribute.rs b/01.workspace/heave/src/str/attribute.rs index 702dfc1..e9aebc1 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: impl ToValue) -> Self { + pub fn new(id: &str, value: impl Into) -> Self { Self { id: String::from(id), - value: value.to_value(), + value: value.into(), } } } diff --git a/01.workspace/heave/src/str/entity.rs b/01.workspace/heave/src/str/entity.rs index df48298..5e05104 100644 --- a/01.workspace/heave/src/str/entity.rs +++ b/01.workspace/heave/src/str/entity.rs @@ -36,7 +36,7 @@ impl O { self.class = class.to_string(); self } - pub fn with_attribute(mut self, id: &str, value: impl ToValue) -> Self { + pub fn with_attribute(mut self, id: &str, value: impl Into) -> Self { let attribute = Attribute::new(id, value); self.attributes.insert(attribute.id.clone(), attribute); self @@ -48,7 +48,7 @@ impl O { Some(attribute) => Some(&attribute.value), } } - pub fn set(&mut self, id: &str, value: impl ToValue) -> Option { + pub fn set(&mut self, id: &str, value: impl Into) -> 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 c86c5a0..3dbacd0 100644 --- a/01.workspace/heave/src/trt/mod.rs +++ b/01.workspace/heave/src/trt/mod.rs @@ -1,4 +1,3 @@ pub mod eav; 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 deleted file mode 100644 index e7521a3..0000000 --- a/01.workspace/heave/src/trt/to_value.rs +++ /dev/null @@ -1,8 +0,0 @@ -use crate::*; - -pub trait T { - fn to_value(self) -> Value; -} - -// #[cfg(test)] -// mod unit_tests {}