Skip to content

Commit

Permalink
Add allocation-free 'Value::from_vec()'
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioBenitez committed Nov 9, 2022
1 parent c11507c commit 2fff05c
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions minijinja/src/value/mod.rs
Expand Up @@ -435,6 +435,28 @@ impl Value {
ValueRepr::Dynamic(value as Arc<dyn Object>).into()
}

/// Creates a value from a vector of values.
///
/// Unlike the existing `TryFrom<Vec<T: Into<Value>>>`, this method involves
/// not additional allocations.
///
/// ```rust
/// use std::sync::Arc;
/// # use minijinja::value::Value;
///
/// let values = (0..10).into_iter()
/// .map(Value::from)
/// .collect::<Vec<_>>();
///
/// let v = Value::from_vec(values);
///
/// let values = Arc::new(vec![Value::from("hello")]);
/// let v = Value::from_vec(values);
/// ```
pub fn from_vec<V: Into<Arc<Vec<Value>>>>(values: V) -> Value {
ValueRepr::Seq(values.into()).into()
}

/// Creates a callable value from a function.
///
/// ```
Expand Down

0 comments on commit 2fff05c

Please sign in to comment.