Replace MultiValue::extend_from_values with from_lua_iter

This commit is contained in:
Alex Orlenko
2024-08-06 01:32:20 +01:00
parent f0a995a357
commit 10999babe0
2 changed files with 6 additions and 6 deletions
+1 -3
View File
@@ -177,9 +177,7 @@ impl<T> DerefMut for Variadic<T> {
impl<T: IntoLua> IntoLuaMulti for Variadic<T> {
#[inline]
fn into_lua_multi(self, lua: &Lua) -> Result<MultiValue> {
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)
}
}
+5 -3
View File
@@ -814,11 +814,13 @@ impl MultiValue {
}
#[inline]
pub(crate) fn extend_from_values(&mut self, iter: impl IntoIterator<Item = Result<Value>>) -> Result<()> {
pub(crate) fn from_lua_iter<T: IntoLua>(lua: &Lua, iter: impl IntoIterator<Item = T>) -> Result<Self> {
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)
}
}