use std::sync::Arc;
use crate::datetime::{NdbDateTime, NdbDuration};
use crate::geometry::Geometry;
use crate::value::core::Value;
impl From<&str> for Value {
fn from(s: &str) -> Self {
Value::String(s.to_owned())
}
}
impl From<String> for Value {
fn from(s: String) -> Self {
Value::String(s)
}
}
impl From<i64> for Value {
fn from(i: i64) -> Self {
Value::Integer(i)
}
}
impl Value {
pub fn from_u64(u: u64) -> Self {
match i64::try_from(u) {
Ok(i) => Value::Integer(i),
Err(_) => Value::Decimal(rust_decimal::Decimal::from(u)),
}
}
pub fn decimal_as_wide_u64(d: &rust_decimal::Decimal) -> Option<u64> {
use rust_decimal::prelude::ToPrimitive;
if d.scale() != 0 {
return None;
}
d.to_u64().filter(|u| i64::try_from(*u).is_err())
}
}
impl From<f64> for Value {
fn from(f: f64) -> Self {
Value::Float(f)
}
}
impl From<bool> for Value {
fn from(b: bool) -> Self {
Value::Bool(b)
}
}
impl From<Vec<u8>> for Value {
fn from(b: Vec<u8>) -> Self {
Value::Bytes(b)
}
}
impl From<NdbDateTime> for Value {
fn from(dt: NdbDateTime) -> Self {
Value::DateTime(dt)
}
}
impl From<NdbDuration> for Value {
fn from(d: NdbDuration) -> Self {
Value::Duration(d)
}
}
impl From<rust_decimal::Decimal> for Value {
fn from(d: rust_decimal::Decimal) -> Self {
Value::Decimal(d)
}
}
impl From<Geometry> for Value {
fn from(g: Geometry) -> Self {
Value::Geometry(g)
}
}
impl From<Vec<f32>> for Value {
fn from(v: Vec<f32>) -> Self {
Value::Vector(v.into())
}
}
impl From<Arc<[f32]>> for Value {
fn from(v: Arc<[f32]>) -> Self {
Value::Vector(v)
}
}
impl From<&[f32]> for Value {
fn from(v: &[f32]) -> Self {
Value::Vector(v.into())
}
}