Port to edition 2024 (#246)

This commit is contained in:
Riccardo Mazzarini 2025-05-23 17:42:12 +02:00 committed by GitHub
parent 68cfa21584
commit 3d3e8d4acc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
94 changed files with 169 additions and 170 deletions

View file

@ -50,10 +50,10 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- run: cargo clippy --features neovim-nightly -- -D warnings
- run: cargo clippy --all-features --workspace --tests -- -D warnings
docs:
name: docs

View file

@ -4,7 +4,7 @@ resolver = "2"
[workspace.package]
version = "0.5.1"
edition = "2021"
edition = "2024"
authors = ["Riccardo Mazzarini <me@noib3.dev>"]
rust-version = "1.62"
description = "Rust bindings to all things Neovim"
@ -26,6 +26,9 @@ thiserror = "2.0"
[workspace.lints.clippy]
mixed_attributes_style = "allow"
[workspace.lints.rust]
unsafe_op_in_unsafe_fn = "allow"
[package]
name = "nvim-oxi"
description.workspace = true

View file

@ -1,12 +1,12 @@
use types::{self as nvim, conversion::FromObject, Array, Integer, Object};
use types::{self as nvim, Array, Integer, Object, conversion::FromObject};
use super::LUA_INTERNAL_CALL;
use super::ffi::autocmd::*;
use super::opts::*;
use super::types::*;
use super::LUA_INTERNAL_CALL;
use crate::choose;
use crate::Result;
use crate::SuperIterator;
use crate::choose;
/// Binding to [`nvim_clear_autocmds()`][1].
///
@ -128,7 +128,7 @@ where
/// [1]: https://neovim.io/doc/user/api.html#nvim_get_autocmds()
pub fn get_autocmds(
opts: &GetAutocmdsOpts,
) -> Result<impl SuperIterator<AutocmdInfos>> {
) -> Result<impl SuperIterator<AutocmdInfos> + use<>> {
let mut err = nvim::Error::new();
let infos = unsafe { nvim_get_autocmds(opts, types::arena(), &mut err) };
choose!(

View file

@ -8,21 +8,21 @@ use luajit::{self as lua, Poppable, Pushable};
use serde::{Deserialize, Serialize};
use types::{
self as nvim,
conversion::{self, FromObject, ToObject},
Array,
BufHandle,
Function,
Integer,
Object,
conversion::{self, FromObject, ToObject},
};
use crate::LUA_INTERNAL_CALL;
use crate::SuperIterator;
use crate::choose;
use crate::ffi::buffer::*;
use crate::opts::*;
use crate::types::{KeymapInfos, Mode};
use crate::utils;
use crate::SuperIterator;
use crate::LUA_INTERNAL_CALL;
use crate::{Error, IntoResult, Result};
/// A wrapper around a Neovim buffer handle.
@ -153,7 +153,7 @@ impl Buffer {
ref_or_nil.as_luaref_unchecked()
},
types::ObjectKind::Nil => {
return Ret::from_object(Object::nil()).map_err(Into::into)
return Ret::from_object(Object::nil()).map_err(Into::into);
},
other => panic!("Unexpected object kind: {other:?}"),
};

View file

@ -1,13 +1,13 @@
use types::{self as nvim, conversion::FromObject};
use super::opts::*;
use crate::Buffer;
use crate::LUA_INTERNAL_CALL;
use crate::Result;
use crate::choose;
use crate::ffi::command::*;
use crate::trait_utils::{StringOrFunction, SuperIterator};
use crate::types::*;
use crate::Buffer;
use crate::Result;
use crate::LUA_INTERNAL_CALL;
/// Binding to [`nvim_cmd()`][1].
///

View file

@ -1,10 +1,10 @@
use types::conversion::{FromObject, ToObject};
use crate::LUA_INTERNAL_CALL;
use crate::Result;
use crate::choose;
use crate::ffi::deprecated::*;
use crate::types::*;
use crate::Result;
use crate::LUA_INTERNAL_CALL;
use crate::{Buffer, Window};
/// Binding to [`nvim_exec()`][1].

View file

@ -1,14 +1,14 @@
use std::ops::RangeBounds;
use types::{self as nvim, conversion::FromObject, Array, Integer};
use types::{self as nvim, Array, Integer, conversion::FromObject};
use crate::Buffer;
use crate::SuperIterator;
use crate::choose;
use crate::ffi::extmark::*;
use crate::opts::*;
use crate::types::*;
use crate::utils;
use crate::Buffer;
use crate::SuperIterator;
use crate::{Error, Result};
/// Binding to [`nvim_create_namespace()`][1].

View file

@ -6,7 +6,7 @@ use crate::opts::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/autocmd.c#L555
pub(crate) fn nvim_clear_autocmds(
opts: *const ClearAutocmdsOpts,

View file

@ -6,7 +6,7 @@ use crate::opts::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/buffer.c#L164
pub(crate) fn nvim_buf_attach(
channel_id: u64,

View file

@ -8,7 +8,7 @@ pub(crate) type ParseCmdOutput = crate::types::ParseCmdOutput;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/command.c#L902
pub(crate) fn nvim_buf_create_user_command(
channel_id: u64,

View file

@ -4,7 +4,7 @@ use types::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/deprecated.c#L559
pub(crate) fn nvim_buf_get_option(
buf: BufHandle,

View file

@ -6,7 +6,7 @@ use crate::opts::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/extmark.c#L919
pub(crate) fn nvim_buf_add_highlight(
buf: BufHandle,

View file

@ -2,7 +2,7 @@
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/private/helpers.c#L776
pub(crate) fn object_to_hl_id(
obj: types::Object,

View file

@ -6,7 +6,7 @@ use crate::opts::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/options.c#L266
pub(crate) fn nvim_get_all_options_info(
arena: *mut Arena,

View file

@ -4,7 +4,7 @@ use types::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/tabpage.c#L87
pub(crate) fn nvim_tabpage_del_var(
tabpage: TabHandle,

View file

@ -6,7 +6,7 @@ use crate::opts::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/vim.c#L1146
pub(crate) fn nvim_chan_send(
chan: Integer,

View file

@ -4,7 +4,7 @@ use types::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/vimscript.c#L278
pub(crate) fn nvim_call_dict_function(
dict: NonOwning<Object>,

View file

@ -8,7 +8,7 @@ pub(crate) type WinGetConfigOutput = WindowOpts;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/win_config.c#L159
pub(crate) fn nvim_open_win(
buffer: BufHandle,

View file

@ -4,7 +4,7 @@ use types::*;
all(target_os = "windows", target_env = "msvc"),
link(name = "nvim.exe", kind = "raw-dylib", modifiers = "+verbatim")
)]
extern "C" {
unsafe extern "C" {
// https://github.com/neovim/neovim/blob/v0.10.0/src/nvim/api/window.c#L428
pub(crate) fn nvim_win_call(
win: WinHandle,

View file

@ -59,19 +59,11 @@ const LUA_INTERNAL_CALL: u64 = VIML_INTERNAL_CALL + 1;
macro_rules! choose {
($err:expr, ()) => {
if $err.is_err() {
Err($err.into())
} else {
Ok(())
}
if $err.is_err() { Err($err.into()) } else { Ok(()) }
};
($err:expr, $other:expr) => {
if $err.is_err() {
Err($err.into())
} else {
$other
}
if $err.is_err() { Err($err.into()) } else { $other }
};
}

View file

@ -3,12 +3,12 @@ use types::{
conversion::{FromObject, ToObject},
};
use crate::Result;
use crate::SuperIterator;
use crate::choose;
use crate::ffi::options::*;
use crate::opts::*;
use crate::types::*;
use crate::Result;
use crate::SuperIterator;
/// Binding to [`nvim_get_all_options_info()`][1].
///

View file

@ -1,6 +1,6 @@
use crate::types::AutocmdCallbackArgs;
use crate::Buffer;
use crate::StringOrInt;
use crate::types::AutocmdCallbackArgs;
pub type ShouldDeleteAutocmd = bool;

View file

@ -1,5 +1,6 @@
use types::conversion::ToObject;
use crate::Buffer;
use crate::types::{
CommandAddr,
CommandArgs,
@ -7,7 +8,6 @@ use crate::types::{
CommandNArgs,
CommandRange,
};
use crate::Buffer;
/// Options passed to [`create_user_command`](crate::create_user_command) and
/// [`Buffer::create_user_command()`](crate::Buffer::create_user_command).

View file

@ -1,7 +1,7 @@
use types::{Array, Object};
use crate::trait_utils::StringOrInt;
use crate::Buffer;
use crate::trait_utils::StringOrInt;
/// Options passed to [`get_autocmds()`](crate::get_autocmds).
#[derive(Clone, Debug, Default, macros::OptsBuilder)]

View file

@ -5,16 +5,16 @@ use luajit::{self as lua, Poppable, Pushable};
use serde::{Deserialize, Serialize};
use types::{
self as nvim,
conversion::{self, FromObject, ToObject},
Object,
TabHandle,
conversion::{self, FromObject, ToObject},
};
use crate::choose;
use crate::ffi::tabpage::*;
use crate::Result;
use crate::SuperIterator;
use crate::Window;
use crate::choose;
use crate::ffi::tabpage::*;
/// A wrapper around a Neovim tab handle.
#[derive(Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]

View file

@ -159,11 +159,7 @@ impl HlGroup for &str {
&mut err,
)
};
if err.is_err() {
Err(err.into())
} else {
Ok(hl_id)
}
if err.is_err() { Err(err.into()) } else { Ok(hl_id) }
}
}

View file

@ -2,9 +2,9 @@ use std::path::PathBuf;
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use crate::Buffer;

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use crate::Buffer;

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use super::ClientInfos;

View file

@ -2,7 +2,7 @@ use std::collections::HashMap;
use std::fmt;
use std::ops::RangeInclusive;
use serde::{de, Deserialize, Serialize};
use serde::{Deserialize, Serialize, de};
#[non_exhaustive]
#[derive(Clone, Debug, Eq, PartialEq, Deserialize)]

View file

@ -1,9 +1,9 @@
use serde::Deserialize;
use types::{
conversion::{self, FromObject, ToObject},
serde::Deserializer,
Array,
Object,
conversion::{self, FromObject, ToObject},
serde::Deserializer,
};
use types::{Boolean, Dictionary, Integer, String as NvimString};

View file

@ -1,8 +1,8 @@
use serde::{Deserialize, Serialize};
use types::{
Object,
conversion::{self, ToObject},
serde::Serializer,
Object,
};
/// See `:h command-addr` for details.

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use crate::serde_utils as utils;

View file

@ -1,9 +1,9 @@
use serde::Serialize;
use types::{
conversion::{self, ToObject},
serde::Serializer,
Function,
Object,
conversion::{self, ToObject},
serde::Serializer,
};
/// See `:h command-complete` for details.

View file

@ -1,12 +1,12 @@
use serde::{
de::{self, Error},
Deserialize,
de::{self, Error},
};
use types::{
conversion::{self, FromObject},
serde::Deserializer,
Function,
Object,
conversion::{self, FromObject},
serde::Deserializer,
};
use super::{CommandAddr, CommandArgs, CommandNArgs, CommandRange};

View file

@ -1,9 +1,9 @@
use serde::{Deserialize, Serialize};
use types::{
conversion::{self, ToObject},
serde::Serializer,
Dictionary,
Object,
conversion::{self, ToObject},
serde::Serializer,
};
use super::SplitModifier;

View file

@ -1,8 +1,8 @@
use serde::{ser, Deserialize, Serialize};
use serde::{Deserialize, Serialize, ser};
use types::{
Object,
conversion::{self, ToObject},
serde::Serializer,
Object,
};
/// Number of arguments accepted by a command.

View file

@ -1,10 +1,10 @@
use std::fmt;
use serde::{de, ser, Serialize};
use serde::{Serialize, de, ser};
use types::{
Object,
conversion::{self, ToObject},
serde::Serializer,
Object,
};
// use crate::object::{self, ToObject};

View file

@ -1,10 +1,10 @@
use serde::Deserialize;
use types::{
conversion::{self, FromObject},
serde::Deserializer,
Array,
Dictionary,
Object,
conversion::{self, FromObject},
serde::Deserializer,
};
#[non_exhaustive]

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use super::{ExtmarkHlMode, ExtmarkVirtTextChunk, ExtmarkVirtTextPosition};

View file

@ -1,11 +1,11 @@
use core::ops::Deref;
use types::{
conversion,
serde::Deserializer,
Dictionary,
Object,
String as NvimString,
conversion,
serde::Deserializer,
};
#[non_exhaustive]

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
/// Attributes related to a highlight group.

View file

@ -1,9 +1,9 @@
use serde::Deserialize;
use types::{
conversion::{self, FromObject},
serde::Deserializer,
Function,
Object,
conversion::{self, FromObject},
serde::Deserializer,
};
use super::Mode;

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
/// Informations related to an option. Unlike in the Lua API, the `type` field

View file

@ -4,11 +4,11 @@ use std::collections::BTreeSet;
use serde::Deserialize;
use types::{
conversion::{self, FromObject},
serde::Deserializer,
Float,
Integer,
Object,
conversion::{self, FromObject},
serde::Deserializer,
};
use super::viml_ast_node::*;

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
#[non_exhaustive]

View file

@ -1,4 +1,4 @@
use serde::{ser, Serialize};
use serde::{Serialize, ser};
use types::{conversion::FromObject, serde::Serializer};
#[non_exhaustive]

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use super::StatuslineHighlightInfos;

View file

@ -1,8 +1,8 @@
use serde::Deserialize;
use types::{
Object,
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use crate::serde_utils as utils;

View file

@ -1,7 +1,7 @@
use serde::de::Deserialize;
use types::Dictionary;
use types::conversion::Error;
use types::serde::Deserializer;
use types::Dictionary;
/// Infos returned by [`Window::text_height()`][crate::Window::text_height].
#[derive(Debug, serde::Deserialize)]

View file

@ -175,13 +175,13 @@ impl<'de> de::Deserialize<'de> for WindowBorder {
other,
&"border styles returned by Neovim always \
contain 8 items",
))
));
},
None => {
return Err(de::Error::custom(
"couldn't determine array length",
))
));
},
};

View file

@ -1,6 +1,6 @@
use std::fmt;
use serde::{de, Deserialize};
use serde::{Deserialize, de};
use types::{Array, Object};
#[non_exhaustive]
@ -74,13 +74,13 @@ impl<'de> Deserialize<'de> for WindowBorderChar {
&"border character in array form expected to \
contain 2 elements representing character and \
highlight group respectively",
))
));
},
None => {
return Err(de::Error::custom(
"couldn't determine array length",
))
));
},
}

View file

@ -1,17 +1,17 @@
use serde::Deserialize;
use types::{
conversion::{self, FromObject},
serde::Deserializer,
Array,
Float,
Integer,
Object,
conversion::{self, FromObject},
serde::Deserializer,
};
use types::{Boolean, String as NvimString, WinHandle};
use super::{WindowAnchor, WindowBorder, WindowRelativeTo, WindowStyle};
use crate::serde_utils as utils;
use crate::Window;
use crate::serde_utils as utils;
#[non_exhaustive]
#[derive(Clone, Debug, Default, PartialEq, Deserialize)]

View file

@ -3,19 +3,19 @@ use std::path::{Path, PathBuf};
use types::NvimStr;
use types::{
self as nvim,
conversion::{FromObject, ToObject},
Array,
Dictionary,
Integer,
Object,
conversion::{FromObject, ToObject},
};
use crate::LUA_INTERNAL_CALL;
use crate::SuperIterator;
use crate::choose;
use crate::ffi::vim::*;
use crate::opts::*;
use crate::types::*;
use crate::SuperIterator;
use crate::LUA_INTERNAL_CALL;
use crate::{Buffer, TabPage, Window};
use crate::{Error, Result};
@ -279,7 +279,9 @@ pub fn get_current_win() -> Window {
pub fn get_hl(
ns_id: u32,
opts: &GetHighlightOpts,
) -> Result<GetHlInfos<impl SuperIterator<(types::String, HighlightInfos)>>> {
) -> Result<
GetHlInfos<impl SuperIterator<(types::String, HighlightInfos)> + use<>>,
> {
let mut err = nvim::Error::new();
let dict = unsafe {
nvim_get_hl(ns_id as Integer, opts, types::arena(), &mut err)

View file

@ -1,10 +1,10 @@
use types::{self as nvim, conversion::FromObject, Array, Object};
use types::{self as nvim, Array, Object, conversion::FromObject};
use crate::Result;
use crate::choose;
use crate::ffi::vimscript::*;
use crate::opts::ExecOpts;
use crate::types::*;
use crate::Result;
/// Binding to [`nvim_call_dict_function()`][1].
///

View file

@ -1,9 +1,9 @@
use types as nvim;
use crate::Result;
use crate::choose;
use crate::ffi::win_config::*;
use crate::types::*;
use crate::Result;
use crate::{Buffer, Window};
/// Binding to [`nvim_open_win()`][1].

View file

@ -6,19 +6,19 @@ use luajit::{self as lua, Poppable, Pushable};
use serde::{Deserialize, Serialize};
use types::{
self as nvim,
conversion::{self, FromObject, ToObject},
Array,
Function,
Integer,
Object,
WinHandle,
conversion::{self, FromObject, ToObject},
};
use crate::Result;
use crate::choose;
use crate::ffi::window::*;
use crate::opts::WinTextHeightOpts;
use crate::types::WinTextHeightInfos;
use crate::Result;
use crate::{Buffer, IntoResult, TabPage};
/// A wrapper around a Neovim window handle.
@ -114,7 +114,7 @@ impl Window {
ref_or_nil.as_luaref_unchecked()
},
types::ObjectKind::Nil => {
return Ret::from_object(Object::nil()).map_err(Into::into)
return Ret::from_object(Object::nil()).map_err(Into::into);
},
other => panic!("Unexpected object kind: {other:?}"),
};

View file

@ -1,6 +1,6 @@
use std::error::Error as StdError;
use crate::{ffi, Error, Handle, IntoResult};
use crate::{Error, Handle, IntoResult, ffi};
type Callback = Box<dyn FnMut() -> Result<(), Box<dyn StdError>> + 'static>;

View file

@ -39,7 +39,7 @@ pub(crate) struct uv_timer_t(uv_timer_s);
impl crate::ProperLayout for uv_timer_t {}
extern "C" {
unsafe extern "C" {
// https://github.com/luvit/luv/blob/master/src/luv.c#L751
pub(crate) fn luv_loop(
lua_state: *mut luajit::ffi::State,

View file

@ -2,7 +2,7 @@ use std::alloc::{self, Layout};
use std::ffi::c_void;
use std::marker::PhantomData;
use crate::{ffi, Error, Result};
use crate::{Error, Result, ffi};
/// TODO: docs
pub(crate) trait ProperLayout: Sized {}

View file

@ -5,11 +5,11 @@ mod handle;
mod r#loop;
mod timer;
pub use r#async::AsyncHandle;
pub use error::Error;
use error::Result;
use handle::{Handle, ProperLayout};
pub use luajit::IntoResult;
pub use r#async::AsyncHandle;
pub use r#loop::init;
use r#loop::with_loop;
pub use luajit::IntoResult;
pub use timer::TimerHandle;

View file

@ -1,7 +1,7 @@
use std::error::Error as StdError;
use std::time::Duration;
use crate::{ffi, Error, Handle, IntoResult};
use crate::{Error, Handle, IntoResult, ffi};
pub(crate) type Callback = Box<
dyn FnMut(&mut TimerHandle) -> Result<(), Box<dyn StdError>> + 'static,

View file

@ -53,7 +53,7 @@ pub type Number = c_double;
all(target_os = "windows", target_env = "msvc"),
link(name = "lua51", kind = "raw-dylib")
)]
extern "C" {
unsafe extern "C" {
// https://www.lua.org/manual/5.1/manual.html#lua_call
pub fn lua_call(L: *mut State, nargs: c_int, nresults: c_int);

View file

@ -1,10 +1,10 @@
use core::error::Error;
use core::ffi::{c_int, CStr};
use core::ffi::{CStr, c_int};
use core::mem;
use core::ptr;
use crate::ffi::{self, State};
use crate::{utils, IntoResult, Poppable, Pushable};
use crate::{IntoResult, Poppable, Pushable, utils};
/// Stores a function in the Lua registry, returning its ref.
pub fn store<F, A, R, O>(fun: F) -> c_int

View file

@ -1,4 +1,5 @@
#![allow(clippy::missing_safety_doc)]
mod error;
pub mod ffi;
pub mod function;

View file

@ -1,9 +1,9 @@
use core::hash::Hash;
use std::collections::HashMap;
use crate::Error;
use crate::ffi::*;
use crate::macros::count;
use crate::Error;
/// Trait implemented for types that can be popped off the Lua stack.
pub trait Poppable: Sized {

View file

@ -1,4 +1,4 @@
use core::ffi::{c_int, CStr};
use core::ffi::{CStr, c_int};
use core::fmt::Display;
use crate::ffi::{self, State};
@ -6,8 +6,10 @@ use crate::ffi::{self, State};
/// Does nothing if the stack is already taller than `n`, grows the stack
/// height to `n` by adding `nil`s if it's not.
pub unsafe fn grow_stack(lstate: *mut State, n: c_int) {
if ffi::lua_gettop(lstate) < n {
ffi::lua_settop(lstate, n);
unsafe {
if ffi::lua_gettop(lstate) < n {
ffi::lua_settop(lstate, n);
}
}
}

View file

@ -283,9 +283,8 @@ impl OptsField<'_> {
field_type = arg_type.clone();
},
BuilderAttribute::Generics(gen) => {
let gen = gen.clone();
generics = Some(quote! { #gen });
BuilderAttribute::Generics(gens) => {
generics = Some(quote! { #gens });
},
BuilderAttribute::Inline(inline) => {

View file

@ -1,8 +1,8 @@
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::{quote, ToTokens};
use quote::{ToTokens, quote};
use syn::parse::{Parse, ParseStream};
use syn::{parse_macro_input, parse_quote, ItemFn, Path, Token};
use syn::{ItemFn, Path, Token, parse_macro_input, parse_quote};
use crate::common::{DuplicateError, Keyed, KeyedAttribute};
@ -22,7 +22,7 @@ pub fn plugin(attr: TokenStream, item: TokenStream) -> TokenStream {
quote! {
#entrypoint
#[no_mangle]
#[unsafe(no_mangle)]
unsafe extern "C" fn #lua_module(
state: *mut #nvim_oxi::lua::ffi::State,
) -> ::core::ffi::c_int {

View file

@ -1,8 +1,8 @@
use proc_macro::TokenStream;
use proc_macro2::{Ident, Span};
use quote::{quote, ToTokens};
use quote::{ToTokens, quote};
use syn::parse::{Parse, ParseStream};
use syn::{parse_macro_input, AttrStyle, ItemFn, LitStr, Meta, Token};
use syn::{AttrStyle, ItemFn, LitStr, Meta, Token, parse_macro_input};
use crate::common::{DuplicateError, Keyed, KeyedAttribute};
use crate::plugin::NvimOxi;

View file

@ -2,9 +2,9 @@ use core::ops::{Deref, DerefMut};
use luajit as lua;
use crate::kvec::{self, KVec};
use crate::NonOwning;
use crate::Object;
use crate::kvec::{self, KVec};
/// A vector of Neovim [`Object`]s.
#[derive(Clone, Default, PartialEq)]

View file

@ -1,7 +1,7 @@
use luajit as lua;
use crate::kvec::{self, KVec};
use crate::{conversion, NonOwning, Object, ObjectKind};
use crate::{NonOwning, Object, ObjectKind, conversion};
/// A vector of Neovim
/// `(`[`String`](crate::String)`, `[`Object`](crate::Object)`)` pairs.

View file

@ -1,5 +1,5 @@
use std::error::Error as StdError;
use std::ffi::{c_char, CStr, CString};
use std::ffi::{CStr, CString, c_char};
use std::fmt;
// https://github.com/neovim/neovim/blob/v0.9.0/src/nvim/api/private/defs.h#L64-L67

View file

@ -4,7 +4,7 @@ use std::ffi::c_int;
use std::fmt;
use std::marker::PhantomData;
use luajit::{self as lua, ffi, IntoResult, Poppable, Pushable};
use luajit::{self as lua, IntoResult, Poppable, Pushable, ffi};
use crate::{Error, LuaRef};

View file

@ -18,7 +18,7 @@ mod str;
mod string;
mod string_builder;
pub use arena::{arena, arena_init, Arena};
pub use arena::{Arena, arena, arena_init};
pub use array::{Array, ArrayFromTupleError};
pub use dictionary::{Dictionary, KeyValuePair};
pub use error::Error;

View file

@ -2,7 +2,7 @@ use std::borrow::Cow;
use std::ffi::c_int;
use std::mem::ManuallyDrop;
use lua::{ffi::*, Poppable, Pushable};
use lua::{Poppable, Pushable, ffi::*};
use luajit as lua;
use crate::{

View file

@ -105,7 +105,7 @@ impl<'de> de::Deserializer<'de> for Deserializer {
return Err(Self::Error::invalid_value(
de::Unexpected::Map,
&"dictionary with a single key-value pair",
))
));
},
};
@ -145,7 +145,7 @@ impl<'de> de::Deserializer<'de> for Deserializer {
return Err(Self::Error::invalid_type(
de::Unexpected::Other(&format!("{other:?}")),
&"Array",
))
));
},
};

View file

@ -1,8 +1,8 @@
use serde::ser::{self, Error};
use super::SerializeError;
use crate::conversion::FromObject;
use crate::Object;
use crate::conversion::FromObject;
/// A struct for serializing Rust values into Neovim `Object`s.
#[non_exhaustive]

View file

@ -8,7 +8,7 @@ use std::path::{Path, PathBuf};
use luajit as lua;
use crate::{conversion, NvimStr, Object, ObjectKind, StringBuilder};
use crate::{NvimStr, Object, ObjectKind, StringBuilder, conversion};
/// Binding to the string type used by Neovim.
///

View file

@ -1,5 +1,5 @@
use nvim_oxi::api::{self, opts::*, types::*, Window};
use nvim_oxi::{print, Dictionary, Function};
use nvim_oxi::api::{self, Window, opts::*, types::*};
use nvim_oxi::{Dictionary, Function, print};
#[nvim_oxi::plugin]
fn api() -> nvim_oxi::Result<Dictionary> {

View file

@ -2,7 +2,7 @@ use std::thread;
use std::time::Duration;
use nvim_oxi::libuv::{AsyncHandle, TimerHandle};
use nvim_oxi::{print, schedule, Result};
use nvim_oxi::{Result, print, schedule};
use tokio::sync::mpsc::{self, UnboundedSender};
use tokio::time;

View file

@ -1,6 +1,6 @@
use nvim_oxi::conversion::{Error as ConversionError, FromObject, ToObject};
use nvim_oxi::serde::{Deserializer, Serializer};
use nvim_oxi::{api, lua, print, Dictionary, Function, Object};
use nvim_oxi::{Dictionary, Function, Object, api, lua, print};
use serde::{Deserialize, Serialize};
#[nvim_oxi::plugin]
@ -62,9 +62,11 @@ impl ToObject for Car {
impl lua::Poppable for Car {
unsafe fn pop(lstate: *mut lua::ffi::State) -> Result<Self, lua::Error> {
let obj = Object::pop(lstate)?;
Self::from_object(obj)
.map_err(lua::Error::pop_error_from_err::<Self, _>)
unsafe {
let obj = Object::pop(lstate)?;
Self::from_object(obj)
.map_err(lua::Error::pop_error_from_err::<Self, _>)
}
}
}
@ -73,9 +75,11 @@ impl lua::Pushable for Car {
self,
lstate: *mut lua::ffi::State,
) -> Result<std::ffi::c_int, lua::Error> {
self.to_object()
.map_err(lua::Error::push_error_from_err::<Self, _>)?
.push(lstate)
unsafe {
self.to_object()
.map_err(lua::Error::push_error_from_err::<Self, _>)?
.push(lstate)
}
}
}

View file

@ -1,5 +1,5 @@
use mlua::prelude::LuaFunction;
use nvim_oxi::{mlua, print, Result};
use nvim_oxi::{Result, mlua, print};
#[nvim_oxi::plugin]
fn mlua() -> Result<()> {

View file

@ -1,6 +1,6 @@
use core::ffi::c_int;
use luajit::{ffi::State, Pushable};
use luajit::{Pushable, ffi::State};
/// The entrypoint of the plugin.
///
@ -11,15 +11,17 @@ pub unsafe fn entrypoint<T>(lua_state: *mut State, body: fn() -> T) -> c_int
where
T: Pushable,
{
types::arena_init();
unsafe {
types::arena_init();
luajit::init(lua_state);
luajit::init(lua_state);
#[cfg(feature = "libuv")]
libuv::init(lua_state);
#[cfg(feature = "libuv")]
libuv::init(lua_state);
match body().push(lua_state) {
Ok(num_pushed) => num_pushed,
Err(lua_err) => luajit::utils::push_error(&lua_err, lua_state),
match body().push(lua_state) {
Ok(num_pushed) => num_pushed,
Err(lua_err) => luajit::utils::push_error(&lua_err, lua_state),
}
}
}

View file

@ -83,7 +83,7 @@ pub mod mlua {
}
pub use error::{Error, Result};
pub use luajit::{dbg, print, IntoResult};
pub use luajit::{IntoResult, dbg, print};
pub use macros::plugin;
#[cfg(feature = "test")]
#[cfg_attr(docsrs, doc(cfg(feature = "test")))]

View file

@ -109,9 +109,7 @@ enum BuildErrorKind {
#[error("couldn't read manifest: {0}")]
CouldntReadManifest(cargo_metadata::Error),
#[error(
"nvim_oxi::tests::build() can only be used inside a build script"
)]
#[error("nvim_oxi::tests::build() can only be used inside a build script")]
NotInBuildScript,
#[error("couldn't get the root package")]

View file

@ -4,6 +4,6 @@ mod terminator;
#[doc(hidden)]
pub mod r#test_macro;
pub use build::{build, BuildError};
pub use build::{BuildError, build};
#[cfg(feature = "test-terminator")]
pub use terminator::{TestFailure, TestTerminator};

View file

@ -1,7 +1,7 @@
[package]
name = "tests"
version = "0.1.0"
edition = "2021"
version = "0.0.0"
edition.workspace = true
publish = false
[lib]

View file

@ -1,5 +1,5 @@
use all_asserts::*;
use nvim_oxi::api::{self, opts::*, Buffer};
use nvim_oxi::api::{self, Buffer, opts::*};
#[nvim_oxi::test]
fn clear_autocmds_current_buf() {

View file

@ -3,7 +3,7 @@ use std::ops;
use std::rc::Rc;
use all_asserts::*;
use nvim_oxi::api::{self, opts::*, types::*, Buffer};
use nvim_oxi::api::{self, Buffer, opts::*, types::*};
#[nvim_oxi::test]
fn buf_attach() {

View file

@ -1,4 +1,4 @@
use nvim_oxi::api::{self, opts::*, types::*, Buffer};
use nvim_oxi::api::{self, Buffer, opts::*, types::*};
#[nvim_oxi::test]
fn add_highlight() {

View file

@ -1,7 +1,7 @@
use std::sync::Arc;
use all_asserts::*;
use nvim_oxi::api::{self, opts::*, types::*, Buffer, Window};
use nvim_oxi::api::{self, Buffer, Window, opts::*, types::*};
use nvim_oxi::mlua::{Error as LuaError, IntoLuaMulti, Lua, Table};
use nvim_oxi::{Dictionary, Object};

View file

@ -1,4 +1,4 @@
use nvim_oxi::api::{self, types::*, Buffer, Window};
use nvim_oxi::api::{self, Buffer, Window, types::*};
#[nvim_oxi::test]
fn open_hsplit() {

View file

@ -1,4 +1,4 @@
use nvim_oxi::api::{self, types::*, Buffer, TabPage, Window};
use nvim_oxi::api::{self, Buffer, TabPage, Window, types::*};
#[nvim_oxi::test]
fn win_call_nil() {