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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/// Options passed to [`Buffer::delete()`](crate::Buffer::delete).
#[derive(Clone, Debug, Default)]
#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
pub struct BufDeleteOpts {
    force: types::Object,
    unload: types::Object,
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl BufDeleteOpts {
    #[inline(always)]
    pub fn builder() -> BufDeleteOptsBuilder {
        BufDeleteOptsBuilder::default()
    }
}

#[derive(Clone, Default)]
#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
pub struct BufDeleteOptsBuilder(BufDeleteOpts);

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl BufDeleteOptsBuilder {
    /// Force deletion ignoring unsaved changes.
    #[inline]
    pub fn force(&mut self, force: bool) -> &mut Self {
        self.0.force = force.into();
        self
    }

    /// If `true` the buffer will only be unloaded, not deleted.
    #[inline]
    pub fn unload(&mut self, unload: bool) -> &mut Self {
        self.0.unload = unload.into();
        self
    }

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

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl From<&BufDeleteOpts> for types::Dictionary {
    fn from(opts: &BufDeleteOpts) -> Self {
        Self::from_iter([
            ("force", opts.force.clone()),
            ("unload", opts.unload.clone()),
        ])
    }
}

/// Options passed to [`Buffer::attach`](crate::Buffer::attach).
#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
#[derive(Clone, Debug, Default, macros::OptsBuilder)]
#[repr(C)]
pub struct BufDeleteOpts {
    #[builder(mask)]
    mask: u64,

    /// Force deletion ignoring unsaved changes.
    #[builder(argtype = "bool")]
    force: types::Boolean,

    /// If `true` the buffer will only be unloaded, not deleted.
    #[builder(argtype = "bool")]
    unload: types::Boolean,
}