Skip to main content

nodedb_types/value/
convert.rs

1// SPDX-License-Identifier: Apache-2.0
2
3//! `From` conversions for [`Value`].
4
5use std::sync::Arc;
6
7use crate::datetime::{NdbDateTime, NdbDuration};
8use crate::geometry::Geometry;
9use crate::value::core::Value;
10
11impl From<&str> for Value {
12    fn from(s: &str) -> Self {
13        Value::String(s.to_owned())
14    }
15}
16
17impl From<String> for Value {
18    fn from(s: String) -> Self {
19        Value::String(s)
20    }
21}
22
23impl From<i64> for Value {
24    fn from(i: i64) -> Self {
25        Value::Integer(i)
26    }
27}
28
29impl From<f64> for Value {
30    fn from(f: f64) -> Self {
31        Value::Float(f)
32    }
33}
34
35impl From<bool> for Value {
36    fn from(b: bool) -> Self {
37        Value::Bool(b)
38    }
39}
40
41impl From<Vec<u8>> for Value {
42    fn from(b: Vec<u8>) -> Self {
43        Value::Bytes(b)
44    }
45}
46
47impl From<NdbDateTime> for Value {
48    fn from(dt: NdbDateTime) -> Self {
49        Value::DateTime(dt)
50    }
51}
52
53impl From<NdbDuration> for Value {
54    fn from(d: NdbDuration) -> Self {
55        Value::Duration(d)
56    }
57}
58
59impl From<rust_decimal::Decimal> for Value {
60    fn from(d: rust_decimal::Decimal) -> Self {
61        Value::Decimal(d)
62    }
63}
64
65impl From<Geometry> for Value {
66    fn from(g: Geometry) -> Self {
67        Value::Geometry(g)
68    }
69}
70
71impl From<Vec<f32>> for Value {
72    fn from(v: Vec<f32>) -> Self {
73        Value::Vector(v.into())
74    }
75}
76
77impl From<Arc<[f32]>> for Value {
78    fn from(v: Arc<[f32]>) -> Self {
79        Value::Vector(v)
80    }
81}
82
83impl From<&[f32]> for Value {
84    fn from(v: &[f32]) -> Self {
85        Value::Vector(v.into())
86    }
87}