From 7dacfa3aa43b81c56a778b84cb7fc06c16641108 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Wed, 9 Nov 2022 15:54:18 -0800 Subject: [PATCH] Add allocation-free 'Value::from_vec()' --- minijinja/src/value/mod.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/minijinja/src/value/mod.rs b/minijinja/src/value/mod.rs index 20f1fe1a..362aae4d 100644 --- a/minijinja/src/value/mod.rs +++ b/minijinja/src/value/mod.rs @@ -435,6 +435,28 @@ impl Value { ValueRepr::Dynamic(value as Arc).into() } + /// Creates a value from a vector of values. + /// + /// Unlike the existing `TryFrom>>`, this method involves + /// no additional allocations. + /// + /// ```rust + /// use std::sync::Arc; + /// # use minijinja::value::Value; + /// + /// let values = (0..10).into_iter() + /// .map(Value::from) + /// .collect::>(); + /// + /// let v = Value::from_vec(values); + /// + /// let values = Arc::new(vec![Value::from("hello")]); + /// let v = Value::from_vec(values); + /// ``` + pub fn from_vec>>>(values: V) -> Value { + ValueRepr::Seq(values.into()).into() + } + /// Creates a callable value from a function. /// /// ```