1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
use types::Boolean;
#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
use types::Object;

/// Options passed to [cmd](crate::cmd).
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct CmdOpts {
    #[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
    output: Object,
    #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
    output: Boolean,
}

impl CmdOpts {
    #[inline(always)]
    pub fn builder() -> CmdOptsBuilder {
        CmdOptsBuilder::default()
    }
}

#[derive(Clone, Default)]
pub struct CmdOptsBuilder(CmdOpts);

impl CmdOptsBuilder {
    #[inline]
    pub fn output(&mut self, output: bool) -> &mut Self {
        #[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
        {
            self.0.output = output.into();
        }
        #[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
        {
            self.0.output = output;
        }
        self
    }

    #[inline]
    pub fn build(&mut self) -> CmdOpts {
        std::mem::take(&mut self.0)
    }
}