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
use crate::types::ContextType;

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

    /// List of [`ContextType`]s to gather, or empty for all.
    #[builder(
        generics = "T: IntoIterator<Item = ContextType>",
        argtype = "T",
        inline = "{0}.into_iter().map(types::String::from).collect()"
    )]
    types: types::Array,
}

/// Options passed to [`get_context()`](crate::get_context).
#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
#[derive(Clone, Debug, Default)]
#[repr(C)]
pub struct GetContextOpts {
    types: types::Object,
}

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl GetContextOpts {
    /// Creates a new [`GetContextOptsBuilder`].
    #[inline]
    pub fn builder() -> GetContextOptsBuilder {
        GetContextOptsBuilder::default()
    }
}

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

#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
impl GetContextOptsBuilder {
    /// List of [`ContextType`]s to gather, or empty for all.
    #[inline]
    pub fn types<T>(&mut self, types: T) -> &mut Self
    where
        T: IntoIterator<Item = ContextType>,
    {
        self.0.types = types
            .into_iter()
            .map(types::String::from)
            .collect::<types::Array>()
            .into();
        self
    }

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