From 10999babe0fc936552437b50fa0aa8bf6f4cf4e8 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Tue, 6 Aug 2024 01:32:20 +0100 Subject: [PATCH] Replace `MultiValue::extend_from_values` with `from_lua_iter` --- src/multi.rs | 4 +--- src/value.rs | 8 +++++--- 2 files changed, 6 insertions(+), 6 deletions(-) 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) } }