Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass Rust closures where the Lua api expects functions #2

Closed
noib3 opened this issue May 25, 2022 · 0 comments
Closed

Pass Rust closures where the Lua api expects functions #2

noib3 opened this issue May 25, 2022 · 0 comments
Projects
Milestone

Comments

@noib3
Copy link
Owner

noib3 commented May 25, 2022

It should be possible to pass a Rust closure everywhere one would pass a Lua function when using the Lua API.

Just as an example, something like

local print_current_modified = function()
  local buf = vim.api.nvim_get_current_buf()

  local is_modified = vim.api.nvim_buf_call(buf, function()
    return vim.api.nvim_buf_get_option(0, "modified")
  end)

  print(is_modified)
end

should become

use nvim_oxi as nvim;

fn print_current_modified() -> nvim::Result<()> {
    let buf = nvim::api::get_current_buf();

    let is_modified = buf.call(|| {
        nvim::Buffer::from(0).get_option::<bool>("modified")
    })?;

    nvim::print!("{is_modified}");

    Ok(())
}

Functions should accept FnOnce or FnMut closures on a case-by-case basis, but always with a 'static bound.

@noib3 noib3 added this to In progress in Roadmap May 25, 2022
@noib3 noib3 added this to the v0.1 milestone May 25, 2022
@noib3 noib3 closed this as completed May 31, 2022
Roadmap automation moved this from Focus to Done May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

No branches or pull requests

1 participant