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

Commit 63e7663

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 45244b3 commit 63e7663

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/value/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ 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 where Value: From<T> {
132+
fn from(value: &[T]) -> Self {
133+
Value::Array(value.iter().map(|x| Value::from(x.clone())).collect())
134+
}
135+
}
129136

130137
impl<T> From<Vec<T>> for Value where Value: From<T> {
131138
fn from(mut value: Vec<T>) -> Self {

0 commit comments

Comments
 (0)