diff --git a/src/multi.rs b/src/multi.rs index f62f15a3..8488f61d 100644 --- a/src/multi.rs +++ b/src/multi.rs @@ -177,9 +177,7 @@ impl DerefMut for Variadic { impl IntoLuaMulti for Variadic { #[inline] fn into_lua_multi(self, lua: &Lua) -> Result { - let mut values = MultiValue::with_capacity(self.0.len()); - values.extend_from_values(self.0.into_iter().map(|val| val.into_lua(lua)))?; - Ok(values) + MultiValue::from_lua_iter(lua, self) } } diff --git a/src/value.rs b/src/value.rs index 3fbe5159..5505d728 100644 --- a/src/value.rs +++ b/src/value.rs @@ -814,11 +814,13 @@ impl MultiValue { } #[inline] - pub(crate) fn extend_from_values(&mut self, iter: impl IntoIterator>) -> Result<()> { + pub(crate) fn from_lua_iter(lua: &Lua, iter: impl IntoIterator) -> Result { + let iter = iter.into_iter(); + let mut multi_value = MultiValue::with_capacity(iter.size_hint().0); for value in iter { - self.push_back(value?); + multi_value.push_back(value.into_lua(lua)?); } - Ok(()) + Ok(multi_value) } }