Skip to content
This repository was archived by the owner on Aug 15, 2021. It is now read-only.

Commit d1e815a

Browse files
committed
Add &str and &[T] From conversions
It made sense to avoid these in the past because they caused allocation. However, in order to fix conversion mismatches with serde, we had to adopt allocation. Since we have now accepted allocation, it now makes sense to add these conversions for ergonomics.
1 parent 1533850 commit d1e815a

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/value/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,16 @@ impl_from!(Value::Integer, u64);
126126
impl_from!(Value::Float, f32);
127127
impl_from!(Value::Float, f64);
128128
impl_from!(Value::Text, String);
129+
impl_from!(Value::Text, &str);
130+
131+
impl<T: Clone> From<&[T]> for Value
132+
where
133+
Value: From<T>,
134+
{
135+
fn from(value: &[T]) -> Self {
136+
Value::Array(value.iter().map(|x| Value::from(x.clone())).collect())
137+
}
138+
}
129139

130140
impl<T> From<Vec<T>> for Value
131141
where

0 commit comments

Comments
 (0)