Skip to content

Instantly share code, notes, and snippets.

@dylanwh
Created May 25, 2025 20:16
Show Gist options
  • Select an option

  • Save dylanwh/46cf19336f87dcce15424df4afb8c35c to your computer and use it in GitHub Desktop.

Select an option

Save dylanwh/46cf19336f87dcce15424df4afb8c35c to your computer and use it in GitHub Desktop.
trait ToLuaArray {
fn to_lua_array(self, lua: &Lua) -> LuaResult<LuaTable>;
}
impl<T, I> ToLuaArray for I
where
I: IntoIterator<Item = T>,
T: IntoLua,
{
fn to_lua_array(self, lua: &Lua) -> LuaResult<LuaTable> {
lua.create_table_from(self.into_iter().enumerate().map(|(i, item)| (i + 1, item)))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment