refactor: remove trait to_value in favor of Into<Value>
This commit is contained in:
@@ -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::*; }
|
||||
@@ -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::*; }
|
||||
@@ -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::*; }
|
||||
@@ -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::*; }
|
||||
@@ -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;
|
||||
|
||||
@@ -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::*; }
|
||||
@@ -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::*; }
|
||||
@@ -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::*; }
|
||||
10
01.workspace/heave/src/imp/value_from_bool.rs
Normal file
10
01.workspace/heave/src/imp/value_from_bool.rs
Normal 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::*; }
|
||||
10
01.workspace/heave/src/imp/value_from_entity.rs
Normal file
10
01.workspace/heave/src/imp/value_from_entity.rs
Normal 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::*; }
|
||||
10
01.workspace/heave/src/imp/value_from_f64.rs
Normal file
10
01.workspace/heave/src/imp/value_from_f64.rs
Normal 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::*; }
|
||||
10
01.workspace/heave/src/imp/value_from_i64.rs
Normal file
10
01.workspace/heave/src/imp/value_from_i64.rs
Normal 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::*; }
|
||||
10
01.workspace/heave/src/imp/value_from_str.rs
Normal file
10
01.workspace/heave/src/imp/value_from_str.rs
Normal 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::*; }
|
||||
10
01.workspace/heave/src/imp/value_from_string.rs
Normal file
10
01.workspace/heave/src/imp/value_from_string.rs
Normal 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::*; }
|
||||
10
01.workspace/heave/src/imp/value_from_u64.rs
Normal file
10
01.workspace/heave/src/imp/value_from_u64.rs
Normal 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::*; }
|
||||
@@ -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 {
|
||||
|
||||
@@ -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<Value>) -> Self {
|
||||
Self {
|
||||
id: String::from(id),
|
||||
value: value.to_value(),
|
||||
value: value.into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Value>) -> 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<Value> {
|
||||
pub fn set(&mut self, id: &str, value: impl Into<Value>) -> Option<Value> {
|
||||
let attribute = Attribute::new(id, value);
|
||||
let previous_attribute = self.attributes.insert(attribute.id.clone(), attribute);
|
||||
match previous_attribute {
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod eav;
|
||||
pub mod from_eav;
|
||||
pub mod to_eav;
|
||||
pub mod to_value;
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
use crate::*;
|
||||
|
||||
pub trait T {
|
||||
fn to_value(self) -> Value;
|
||||
}
|
||||
|
||||
// #[cfg(test)]
|
||||
// mod unit_tests {}
|
||||
Reference in New Issue
Block a user