nvim_oxi_api/opts/
set_keymap.rs1#[cfg(not(feature = "neovim-0-10"))] use types::Object;
3#[cfg(feature = "neovim-0-10")] use types::{Boolean, LuaRef};
5
6use crate::ToFunction;
7
8#[cfg(feature = "neovim-0-10")] #[derive(Clone, Debug, Default, PartialEq, macros::OptsBuilder)]
12#[repr(C)]
13pub struct SetKeymapOpts {
14 #[builder(mask)]
15 mask: u64,
16
17 #[builder(argtype = "bool")]
19 noremap: Boolean,
20
21 #[builder(argtype = "bool")]
25 nowait: Boolean,
26
27 #[builder(argtype = "bool")]
29 silent: Boolean,
30
31 #[builder(argtype = "bool")]
34 script: Boolean,
35
36 #[builder(argtype = "bool")]
38 expr: Boolean,
39
40 #[builder(argtype = "bool")]
43 unique: Boolean,
44
45 #[builder(
47 generics = "F: ToFunction<(), ()>",
48 argtype = "F",
49 inline = "{0}.into_luaref()"
50 )]
51 callback: LuaRef,
52
53 #[builder(
55 generics = "D: Into<types::String>",
56 argtype = "D",
57 inline = "{0}.into()"
58 )]
59 desc: types::String,
60
61 #[builder(argtype = "bool")]
65 replace_keycodes: Boolean,
66}
67
68#[cfg(not(feature = "neovim-0-10"))] #[derive(Clone, Debug, Default, PartialEq)]
72#[repr(C)]
73pub struct SetKeymapOpts {
74 desc: Object,
75 expr: Object,
76 script: Object,
77 silent: Object,
78 unique: Object,
79 nowait: Object,
80 noremap: Object,
81 callback: Object,
82 replace_keycodes: Object,
83}
84
85#[cfg(not(feature = "neovim-0-10"))] impl SetKeymapOpts {
87 #[inline(always)]
88 pub fn builder() -> SetKeymapOptsBuilder {
90 SetKeymapOptsBuilder::default()
91 }
92}
93
94#[cfg(not(feature = "neovim-0-10"))] #[derive(Clone, Default)]
96pub struct SetKeymapOptsBuilder(SetKeymapOpts);
97
98#[cfg(not(feature = "neovim-0-10"))] impl SetKeymapOptsBuilder {
100 #[inline]
102 pub fn callback<F>(&mut self, fun: F) -> &mut Self
103 where
104 F: ToFunction<(), ()>,
105 {
106 let callback = fun.into_luaref();
107 self.0.callback = Object::from_luaref(callback);
108 self
109 }
110
111 #[inline]
113 pub fn desc(&mut self, desc: &str) -> &mut Self {
114 let desc = types::String::from(desc);
115 self.0.desc = desc.into();
116 self
117 }
118
119 #[inline]
121 pub fn expr(&mut self, expr: bool) -> &mut Self {
122 self.0.expr = expr.into();
123 self
124 }
125
126 #[inline]
128 pub fn noremap(&mut self, noremap: bool) -> &mut Self {
129 self.0.noremap = noremap.into();
130 self
131 }
132
133 #[inline]
137 pub fn nowait(&mut self, nowait: bool) -> &mut Self {
138 self.0.nowait = nowait.into();
139 self
140 }
141
142 #[inline]
146 pub fn replace_keycodes(&mut self, replace_keycodes: bool) -> &mut Self {
147 self.0.replace_keycodes = replace_keycodes.into();
148 self
149 }
150
151 #[inline]
154 pub fn script(&mut self, script: bool) -> &mut Self {
155 self.0.script = script.into();
156 self
157 }
158
159 #[inline]
161 pub fn silent(&mut self, silent: bool) -> &mut Self {
162 self.0.silent = silent.into();
163 self
164 }
165
166 #[inline]
169 pub fn unique(&mut self, unique: bool) -> &mut Self {
170 self.0.unique = unique.into();
171 self
172 }
173
174 #[inline]
175 pub fn build(&mut self) -> SetKeymapOpts {
176 std::mem::take(&mut self.0)
177 }
178}