nvim_oxi_api/opts/
create_autocmd.rs1use crate::types::AutocmdCallbackArgs;
2use crate::Buffer;
3use crate::StringOrInt;
4
5pub type ShouldDeleteAutocmd = bool;
6
7#[cfg(feature = "neovim-0-10")] #[derive(Clone, Debug, Default, macros::OptsBuilder)]
10#[repr(C)]
11pub struct CreateAutocmdOpts {
12 #[builder(mask)]
13 mask: u64,
14
15 #[builder(argtype = "Buffer", inline = "{0}.0")]
17 buffer: types::BufHandle,
18
19 #[builder(
22 generics = r#"F: Into<types::Function<AutocmdCallbackArgs, ShouldDeleteAutocmd>>"#,
23 argtype = "F",
24 inline = "{0}.into().into()"
25 )]
26 callback: types::Object,
27
28 #[builder(
32 generics = "S: Into<types::String>",
33 argtype = "S",
34 inline = "{0}.into()"
35 )]
36 command: types::String,
37
38 #[builder(
41 generics = "S: Into<types::String>",
42 argtype = "S",
43 inline = "{0}.into()"
44 )]
45 desc: types::String,
46
47 #[builder(
49 generics = "G: StringOrInt",
50 argtype = "G",
51 inline = "{0}.to_object()"
52 )]
53 group: types::Object,
54
55 #[builder(argtype = "bool")]
57 nested: types::Boolean,
58
59 #[builder(argtype = "bool")]
61 once: types::Boolean,
62
63 #[builder(
65 generics = "'a, I: IntoIterator<Item = &'a str>",
66 method = "patterns",
67 argtype = "I",
68 inline = "types::Array::from_iter({0}).into()"
69 )]
70 pattern: types::Object,
71}
72
73#[cfg(not(feature = "neovim-0-10"))] #[derive(Clone, Debug, Default)]
76#[repr(C)]
77pub struct CreateAutocmdOpts {
78 desc: types::Object,
79 once: types::Object,
80 group: types::Object,
81 buffer: types::Object,
82 nested: types::Object,
83 command: types::Object,
84 pattern: types::Object,
85 callback: types::Object,
86}
87
88#[cfg(not(feature = "neovim-0-10"))] impl CreateAutocmdOpts {
90 #[inline(always)]
91 pub fn builder() -> CreateAutocmdOptsBuilder {
92 CreateAutocmdOptsBuilder::default()
93 }
94}
95
96#[cfg(not(feature = "neovim-0-10"))] #[derive(Clone, Default)]
98pub struct CreateAutocmdOptsBuilder(CreateAutocmdOpts);
99
100#[cfg(not(feature = "neovim-0-10"))] impl CreateAutocmdOptsBuilder {
102 #[inline]
104 pub fn buffer(&mut self, buffer: Buffer) -> &mut Self {
105 self.0.buffer = buffer.into();
106 self
107 }
108
109 #[inline]
112 pub fn callback<F>(&mut self, callback: F) -> &mut Self
113 where
114 F: Into<types::Function<AutocmdCallbackArgs, ShouldDeleteAutocmd>>,
115 {
116 self.0.callback = callback.into().into();
117 self
118 }
119
120 #[inline]
123 pub fn command<S>(&mut self, command: S) -> &mut Self
124 where
125 S: Into<types::String>,
126 {
127 self.0.command = command.into().into();
128 self
129 }
130
131 #[inline]
133 pub fn desc<S>(&mut self, desc: S) -> &mut Self
134 where
135 S: Into<types::String>,
136 {
137 self.0.desc = desc.into().into();
138 self
139 }
140
141 #[inline]
143 pub fn group<Grp>(&mut self, group: Grp) -> &mut Self
144 where
145 Grp: StringOrInt,
146 {
147 self.0.group = group.to_object();
148 self
149 }
150
151 #[inline]
153 pub fn nested(&mut self, nested: bool) -> &mut Self {
154 self.0.nested = nested.into();
155 self
156 }
157
158 #[inline]
160 pub fn once(&mut self, once: bool) -> &mut Self {
161 self.0.once = once.into();
162 self
163 }
164
165 #[inline]
167 pub fn patterns<'a, I>(&mut self, patterns: I) -> &mut Self
168 where
169 I: IntoIterator<Item = &'a str>,
170 {
171 self.0.pattern = types::Array::from_iter(patterns).into();
172 self
173 }
174
175 #[inline]
176 pub fn build(&mut self) -> CreateAutocmdOpts {
177 std::mem::take(&mut self.0)
178 }
179}