refactor: remove trait to_value in favor of Into<Value>

This commit is contained in:
2025-09-30 07:04:26 +02:00
parent 90fa4119dd
commit af860bdb22
20 changed files with 89 additions and 91 deletions

View File

@@ -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::*; }

View File

@@ -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::*; }

View File

@@ -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::*; }

View File

@@ -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::*; }

View File

@@ -1,13 +1,20 @@
pub mod bool_from_value; pub mod bool_from_value;
pub mod bool_to_value; // pub mod bool_to_value;
pub mod entity_from_value; pub mod entity_from_value;
pub mod entity_to_value; // pub mod entity_to_value;
pub mod f64_from_value; pub mod f64_from_value;
pub mod f64_to_value; // pub mod f64_to_value;
pub mod i64_from_value; pub mod i64_from_value;
pub mod i64_to_value; // pub mod i64_to_value;
pub mod str_to_value; // pub mod str_to_value;
pub mod string_from_value; pub mod string_from_value;
pub mod string_to_value; // pub mod string_to_value;
pub mod u64_from_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;

View File

@@ -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::*; }

View File

@@ -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::*; }

View File

@@ -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::*; }

View File

@@ -0,0 +1,10 @@
use crate::*;
impl From<bool> for Value {
fn from(value: bool) -> Self {
Self::Bool(value)
}
}
// #[cfg(test)]
// mod unit_tests { use super::*; }

View File

@@ -0,0 +1,10 @@
use crate::*;
impl From<Entity> for Value {
fn from(value: Entity) -> Self {
Self::Text(value.id)
}
}
// #[cfg(test)]
// mod unit_tests { use super::*; }

View File

@@ -0,0 +1,10 @@
use crate::*;
impl From<f64> for Value {
fn from(value: f64) -> Self {
Self::Real(value)
}
}
// #[cfg(test)]
// mod unit_tests { use super::*; }

View File

@@ -0,0 +1,10 @@
use crate::*;
impl From<i64> for Value {
fn from(value: i64) -> Self {
Self::SignedInt(value)
}
}
// #[cfg(test)]
// mod unit_tests { use super::*; }

View File

@@ -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::*; }

View File

@@ -0,0 +1,10 @@
use crate::*;
impl From<String> for Value {
fn from(value: String) -> Self {
Self::Text(value)
}
}
// #[cfg(test)]
// mod unit_tests { use super::*; }

View File

@@ -0,0 +1,10 @@
use crate::*;
impl From<u64> for Value {
fn from(value: u64) -> Self {
Self::UnsignedInt(value)
}
}
// #[cfg(test)]
// mod unit_tests { use super::*; }

View File

@@ -14,7 +14,7 @@ pub use crate::str::value::E as Value;
pub use crate::trt::eav::T as EAV; pub use crate::trt::eav::T as EAV;
pub use crate::trt::from_eav::T as FromEAV; pub use crate::trt::from_eav::T as FromEAV;
pub use crate::trt::to_eav::T as ToEAV; 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 { mod sqlite {
pub mod init { pub mod init {

View File

@@ -7,10 +7,10 @@ pub struct O {
} }
impl O { impl O {
pub fn new(id: &str, value: impl ToValue) -> Self { pub fn new(id: &str, value: impl Into<Value>) -> Self {
Self { Self {
id: String::from(id), id: String::from(id),
value: value.to_value(), value: value.into(),
} }
} }
} }

View File

@@ -36,7 +36,7 @@ impl O {
self.class = class.to_string(); self.class = class.to_string();
self self
} }
pub fn with_attribute(mut self, id: &str, value: impl ToValue) -> Self { pub fn with_attribute(mut self, id: &str, value: impl Into<Value>) -> Self {
let attribute = Attribute::new(id, value); let attribute = Attribute::new(id, value);
self.attributes.insert(attribute.id.clone(), attribute); self.attributes.insert(attribute.id.clone(), attribute);
self self
@@ -48,7 +48,7 @@ impl O {
Some(attribute) => Some(&attribute.value), Some(attribute) => Some(&attribute.value),
} }
} }
pub fn set(&mut self, id: &str, value: impl ToValue) -> Option<Value> { pub fn set(&mut self, id: &str, value: impl Into<Value>) -> Option<Value> {
let attribute = Attribute::new(id, value); let attribute = Attribute::new(id, value);
let previous_attribute = self.attributes.insert(attribute.id.clone(), attribute); let previous_attribute = self.attributes.insert(attribute.id.clone(), attribute);
match previous_attribute { match previous_attribute {

View File

@@ -1,4 +1,3 @@
pub mod eav; pub mod eav;
pub mod from_eav; pub mod from_eav;
pub mod to_eav; pub mod to_eav;
pub mod to_value;

View File

@@ -1,8 +0,0 @@
use crate::*;
pub trait T {
fn to_value(self) -> Value;
}
// #[cfg(test)]
// mod unit_tests {}