nvim_oxi_api/opts/
get_context.rs

1use crate::types::ContextType;
2
3/// Options passed to [`get_context()`](crate::get_context).
4#[cfg(feature = "neovim-0-10")] // On 0.10 and nightly.
5#[derive(Clone, Debug, Default, macros::OptsBuilder)]
6#[repr(C)]
7pub struct GetContextOpts {
8    #[builder(mask)]
9    mask: u64,
10
11    /// List of [`ContextType`]s to gather, or empty for all.
12    #[builder(
13        generics = "T: IntoIterator<Item = ContextType>",
14        argtype = "T",
15        inline = "{0}.into_iter().map(types::String::from).collect()"
16    )]
17    types: types::Array,
18}
19
20/// Options passed to [`get_context()`](crate::get_context).
21#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
22#[derive(Clone, Debug, Default)]
23#[repr(C)]
24pub struct GetContextOpts {
25    types: types::Object,
26}
27
28#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
29impl GetContextOpts {
30    /// Creates a new [`GetContextOptsBuilder`].
31    #[inline]
32    pub fn builder() -> GetContextOptsBuilder {
33        GetContextOptsBuilder::default()
34    }
35}
36
37#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
38#[derive(Clone, Default)]
39pub struct GetContextOptsBuilder(GetContextOpts);
40
41#[cfg(not(feature = "neovim-0-10"))] // 0nly on 0.9.
42impl GetContextOptsBuilder {
43    /// List of [`ContextType`]s to gather, or empty for all.
44    #[inline]
45    pub fn types<T>(&mut self, types: T) -> &mut Self
46    where
47        T: IntoIterator<Item = ContextType>,
48    {
49        self.0.types = types
50            .into_iter()
51            .map(types::String::from)
52            .collect::<types::Array>()
53            .into();
54        self
55    }
56
57    #[inline]
58    pub fn build(&mut self) -> GetContextOpts {
59        std::mem::take(&mut self.0)
60    }
61}