nvim_api/opts/
exec_autocmds.rs1use derive_builder::Builder;
2use nvim_types::{NonOwning, Object};
3
4use crate::Buffer;
5use crate::StringOrInt;
6
7#[derive(Clone, Debug, Default, Builder)]
9#[builder(default, build_fn(private, name = "fallible_build"))]
10pub struct ExecAutocmdsOpts {
11 #[builder(setter(into, strip_option))]
14 buffer: Option<Buffer>,
15
16 #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
17 #[cfg_attr(
18 docsrs,
19 doc(cfg(any(feature = "neovim-0-8", feature = "neovim-nightly")))
20 )]
21 #[builder(setter(custom))]
22 data: Object,
23
24 #[builder(setter(custom))]
25 group: Object,
26
27 modeline: bool,
29
30 #[builder(setter(custom))]
31 patterns: Object,
32}
33
34impl ExecAutocmdsOpts {
35 #[inline(always)]
36 pub fn builder() -> ExecAutocmdsOptsBuilder {
37 ExecAutocmdsOptsBuilder::default()
38 }
39}
40
41impl ExecAutocmdsOptsBuilder {
42 #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
43 #[cfg_attr(
44 docsrs,
45 doc(cfg(any(feature = "neovim-0-8", feature = "neovim-nightly")))
46 )]
47 pub fn data(&mut self, any: impl Into<Object>) -> &mut Self {
48 self.data = Some(any.into());
49 self
50 }
51
52 pub fn group<Grp>(&mut self, group: Grp) -> &mut Self
54 where
55 Grp: StringOrInt,
56 {
57 self.group = Some(group.to_object());
58 self
59 }
60
61 #[cfg(feature = "neovim-0-7")]
66 pub fn patterns(&mut self, patterns: &str) -> &mut Self {
67 self.patterns = Some(patterns.into());
68 self
69 }
70
71 #[cfg(not(feature = "neovim-0-7"))]
74 pub fn patterns<Patterns>(&mut self, patterns: Patterns) -> &mut Self
75 where
76 Patterns: crate::trait_utils::StringOrListOfStrings,
77 {
78 self.patterns = Some(patterns.to_object());
79 self
80 }
81
82 pub fn build(&mut self) -> ExecAutocmdsOpts {
83 self.fallible_build().expect("never fails, all fields have defaults")
84 }
85}
86
87#[derive(Default)]
88#[allow(non_camel_case_types)]
89#[repr(C)]
90pub(crate) struct KeyDict_exec_autocmds<'a> {
91 #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
92 data: NonOwning<'a, Object>,
93 group: NonOwning<'a, Object>,
94 buffer: Object,
95 pattern: NonOwning<'a, Object>,
96 modeline: Object,
97}
98
99impl<'a> From<&'a ExecAutocmdsOpts> for KeyDict_exec_autocmds<'a> {
100 fn from(opts: &'a ExecAutocmdsOpts) -> KeyDict_exec_autocmds<'a> {
101 Self {
102 #[cfg(any(feature = "neovim-0-8", feature = "neovim-nightly"))]
103 data: opts.data.non_owning(),
104 group: opts.group.non_owning(),
105 buffer: opts.buffer.as_ref().into(),
106 pattern: opts.patterns.non_owning(),
107 modeline: opts.modeline.into(),
108 }
109 }
110}