Skip to main content

reddb_server/storage/unified/devx/
conversions.rs

1//! Value Conversions for Ergonomics
2//!
3//! From implementations for Value and MetadataValue for fluent API.
4
5use super::super::{MetadataValue, RefTarget};
6use super::refs::{NodeRef, TableRef, VectorRef};
7
8// ============================================================================
9// Value Conversions
10// ============================================================================
11//
12// The `From<primitive> for Value` impls were re-homed to the keystone crate
13// `reddb-io-types` alongside `Value` itself (ADR 0052, #1061): with `Value`
14// no longer local here, the orphan rule requires those impls to live in
15// `Value`'s home crate. See `reddb_types::conversions`.
16
17// ============================================================================
18// MetadataValue Conversions
19// ============================================================================
20
21impl From<&str> for MetadataValue {
22    fn from(s: &str) -> Self {
23        MetadataValue::String(s.to_string())
24    }
25}
26
27impl From<String> for MetadataValue {
28    fn from(s: String) -> Self {
29        MetadataValue::String(s)
30    }
31}
32
33impl From<i64> for MetadataValue {
34    fn from(n: i64) -> Self {
35        MetadataValue::Int(n)
36    }
37}
38
39impl From<f64> for MetadataValue {
40    fn from(n: f64) -> Self {
41        MetadataValue::Float(n)
42    }
43}
44
45impl From<bool> for MetadataValue {
46    fn from(b: bool) -> Self {
47        MetadataValue::Bool(b)
48    }
49}
50
51impl From<RefTarget> for MetadataValue {
52    fn from(r: RefTarget) -> Self {
53        MetadataValue::Reference(r)
54    }
55}
56
57impl From<Vec<RefTarget>> for MetadataValue {
58    fn from(refs: Vec<RefTarget>) -> Self {
59        MetadataValue::References(refs)
60    }
61}
62
63impl From<TableRef> for MetadataValue {
64    fn from(r: TableRef) -> Self {
65        MetadataValue::Reference(RefTarget::table(r.table, r.row_id))
66    }
67}
68
69impl From<NodeRef> for MetadataValue {
70    fn from(r: NodeRef) -> Self {
71        MetadataValue::Reference(RefTarget::node(r.collection, r.node_id))
72    }
73}
74
75impl From<VectorRef> for MetadataValue {
76    fn from(r: VectorRef) -> Self {
77        MetadataValue::Reference(RefTarget::vector(r.collection, r.vector_id))
78    }
79}