use derive_builder::Builder;
use nvim_types::{self as nvim, NonOwning, Object};
use crate::ToFunction;
#[derive(Clone, Debug, Default, PartialEq, Builder)]
#[builder(default, build_fn(private, name = "fallible_build"))]
pub struct SetKeymapOpts {
#[builder(setter(custom))]
callback: Object,
#[builder(setter(custom))]
desc: Object,
#[builder(setter(strip_option))]
expr: Option<bool>,
#[builder(setter(strip_option))]
noremap: Option<bool>,
#[builder(setter(strip_option))]
nowait: Option<bool>,
#[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
#[cfg_attr(
docsrs,
doc(cfg(any(feature = "neovim-0-8", feature = "neovim-nightly")))
)]
#[builder(setter(strip_option))]
replace_keycodes: Option<bool>,
#[builder(setter(strip_option))]
script: Option<bool>,
#[builder(setter(strip_option))]
silent: Option<bool>,
#[builder(setter(strip_option))]
unique: Option<bool>,
}
impl SetKeymapOpts {
#[inline(always)]
pub fn builder() -> SetKeymapOptsBuilder {
SetKeymapOptsBuilder::default()
}
}
impl SetKeymapOptsBuilder {
pub fn callback<F>(&mut self, fun: F) -> &mut Self
where
F: ToFunction<(), ()>,
{
self.callback = Some(fun.to_object());
self
}
pub fn desc(&mut self, desc: &str) -> &mut Self {
self.desc = Some(nvim::String::from(desc).into());
self
}
pub fn build(&mut self) -> SetKeymapOpts {
self.fallible_build().expect("never fails, all fields have defaults")
}
}
#[derive(Default)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub(crate) struct KeyDict_keymap<'a> {
desc: NonOwning<'a, Object>,
expr: Object,
script: Object,
silent: Object,
unique: Object,
nowait: Object,
noremap: Object,
callback: NonOwning<'a, Object>,
#[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
replace_keycodes: Object,
}
impl<'a> From<&'a SetKeymapOpts> for KeyDict_keymap<'a> {
fn from(opts: &'a SetKeymapOpts) -> Self {
Self {
desc: opts.desc.non_owning(),
expr: opts.expr.into(),
script: opts.script.into(),
silent: opts.silent.into(),
unique: opts.unique.into(),
nowait: opts.nowait.into(),
noremap: opts.noremap.into(),
callback: opts.callback.non_owning(),
#[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
replace_keycodes: opts.replace_keycodes.into(),
}
}
}