use nvim_types::{
conversion::{self, FromObject},
serde::Deserializer,
Object,
};
use serde::Deserialize;
use crate::serde_utils as utils;
#[non_exhaustive]
#[derive(Clone, Debug, Eq, PartialEq, Hash, Deserialize)]
pub struct CommandArgs {
#[serde(deserialize_with = "utils::empty_string_is_none")]
pub args: Option<String>,
pub bang: bool,
#[serde(deserialize_with = "utils::minus_one_is_none")]
pub count: Option<u32>,
pub fargs: Vec<String>,
pub line1: usize,
pub line2: usize,
#[serde(deserialize_with = "utils::empty_string_is_none")]
pub mods: Option<String>,
pub range: u8,
#[serde(rename = "reg", deserialize_with = "utils::empty_string_is_none")]
pub register: Option<String>,
#[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
#[cfg_attr(
docsrs,
doc(cfg(any(feature = "neovim-0-8", feature = "neovim-nightly")))
)]
pub smods: super::CommandModifiers,
}
impl FromObject for CommandArgs {
fn from_object(obj: Object) -> Result<Self, conversion::Error> {
Self::deserialize(Deserializer::new(obj)).map_err(Into::into)
}
}
impl luajit_bindings::Poppable for CommandArgs {
unsafe fn pop(
lstate: *mut luajit_bindings::ffi::lua_State,
) -> Result<Self, luajit_bindings::Error> {
let obj = Object::pop(lstate)?;
Self::from_object(obj)
.map_err(luajit_bindings::Error::pop_error_from_err::<Self, _>)
}
}