use crate::model::conversion::ToDataValue;
use crate::types::DataValue;
impl ToDataValue for String {
fn to_data_value(&self) -> DataValue {
DataValue::String(self.clone())
}
}
impl ToDataValue for &str {
fn to_data_value(&self) -> DataValue {
DataValue::String(self.to_string())
}
}
impl ToDataValue for i32 {
fn to_data_value(&self) -> DataValue {
DataValue::Int(*self as i64)
}
}
impl ToDataValue for i64 {
fn to_data_value(&self) -> DataValue {
DataValue::Int(*self)
}
}
impl ToDataValue for u8 {
fn to_data_value(&self) -> DataValue {
DataValue::UInt(*self as u64)
}
}
impl ToDataValue for u16 {
fn to_data_value(&self) -> DataValue {
DataValue::UInt(*self as u64)
}
}
impl ToDataValue for u32 {
fn to_data_value(&self) -> DataValue {
DataValue::UInt(*self as u64)
}
}
impl ToDataValue for u64 {
fn to_data_value(&self) -> DataValue {
DataValue::UInt(*self)
}
}
impl ToDataValue for usize {
fn to_data_value(&self) -> DataValue {
DataValue::UInt(*self as u64)
}
}
impl ToDataValue for f32 {
fn to_data_value(&self) -> DataValue {
DataValue::Float(*self as f64)
}
}
impl ToDataValue for f64 {
fn to_data_value(&self) -> DataValue {
DataValue::Float(*self)
}
}
impl ToDataValue for bool {
fn to_data_value(&self) -> DataValue {
DataValue::Bool(*self)
}
}
impl ToDataValue for chrono::DateTime<chrono::Utc> {
fn to_data_value(&self) -> DataValue {
let fixed_dt = self.with_timezone(&chrono::FixedOffset::east(0));
DataValue::DateTime(fixed_dt)
}
}
impl ToDataValue for chrono::DateTime<chrono::FixedOffset> {
fn to_data_value(&self) -> DataValue {
DataValue::DateTime(*self)
}
}
impl ToDataValue for uuid::Uuid {
fn to_data_value(&self) -> DataValue {
DataValue::Uuid(*self)
}
}
impl ToDataValue for serde_json::Value {
fn to_data_value(&self) -> DataValue {
DataValue::Json(self.clone())
}
}
impl<T> ToDataValue for Option<T>
where
T: ToDataValue,
{
fn to_data_value(&self) -> DataValue {
match self {
Some(v) => v.to_data_value(),
None => DataValue::Null,
}
}
}