|
1 |
| -use crate::{Key, StringValue}; |
| 1 | +use crate::{Array, Key, StringValue, Value}; |
2 | 2 |
|
3 | 3 | use crate::{SpanId, TraceFlags, TraceId};
|
4 | 4 |
|
@@ -121,6 +121,28 @@ impl From<&[u8]> for AnyValue {
|
121 | 121 | }
|
122 | 122 | }
|
123 | 123 |
|
| 124 | +impl From<&Value> for AnyValue { |
| 125 | + fn from(value: &Value) -> Self { |
| 126 | + match value { |
| 127 | + Value::Bool(b) => AnyValue::Boolean(*b), |
| 128 | + Value::I64(i) => AnyValue::Int(*i), |
| 129 | + Value::F64(f) => AnyValue::Double(*f), |
| 130 | + Value::String(s) => AnyValue::String(s.clone()), |
| 131 | + Value::Array(a) => { |
| 132 | + let v = match a { |
| 133 | + Array::Bool(items) => items.iter().map(|b| AnyValue::Boolean(*b)).collect(), |
| 134 | + Array::I64(items) => items.iter().map(|i| AnyValue::Int(*i)).collect(), |
| 135 | + Array::F64(items) => items.iter().map(|f| AnyValue::Double(*f)).collect(), |
| 136 | + Array::String(items) => { |
| 137 | + items.iter().map(|s| AnyValue::String(s.clone())).collect() |
| 138 | + } |
| 139 | + }; |
| 140 | + AnyValue::ListAny(Box::new(v)) |
| 141 | + } |
| 142 | + } |
| 143 | + } |
| 144 | +} |
| 145 | + |
124 | 146 | impl<T: Into<AnyValue>> FromIterator<T> for AnyValue {
|
125 | 147 | /// Creates an [`AnyValue::ListAny`] value from a sequence of `Into<AnyValue>` values.
|
126 | 148 | fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
|
|
0 commit comments