nvim_api/opts/
get_context.rs1use derive_builder::Builder;
2use nvim_types::{self as nvim, Array, NonOwning, Object};
3
4use crate::types::ContextType;
5
6#[derive(Clone, Debug, Default, Builder)]
8#[builder(default, build_fn(private, name = "fallible_build"))]
9pub struct GetContextOpts {
10 #[builder(setter(custom))]
11 types: Object,
12}
13
14impl GetContextOpts {
15 #[inline(always)]
16 pub fn builder() -> GetContextOptsBuilder {
18 GetContextOptsBuilder::default()
19 }
20}
21
22impl GetContextOptsBuilder {
23 pub fn types<T: IntoIterator<Item = ContextType>>(
25 &mut self,
26 types: T,
27 ) -> &mut Self {
28 self.types = Some(
29 types
30 .into_iter()
31 .map(nvim::String::from)
32 .collect::<Array>()
33 .into(),
34 );
35 self
36 }
37
38 pub fn build(&mut self) -> GetContextOpts {
39 self.fallible_build().expect("never fails, all fields have defaults")
40 }
41}
42
43#[derive(Default, Debug)]
44#[allow(non_camel_case_types)]
45#[repr(C)]
46pub(crate) struct KeyDict_context<'a> {
47 types: NonOwning<'a, Object>,
48}
49
50impl<'a> From<&'a GetContextOpts> for KeyDict_context<'a> {
51 fn from(opts: &'a GetContextOpts) -> Self {
52 Self { types: opts.types.non_owning() }
53 }
54}