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
69
70
71
72
73
74
75
76
77
78
79
80
81
use derive_builder::Builder;
use nvim_types::{self as nvim, NonOwning, Object};
use serde::Serialize;
use crate::object;
#[derive(Clone, Debug, Default, Builder)]
#[builder(default, build_fn(private, name = "fallible_build"))]
pub struct OptionValueOpts {
#[cfg(feature = "nightly")]
#[cfg_attr(docsrs, doc(cfg(feature = "nightly")))]
#[builder(setter(strip_option))]
buffer: Option<crate::api::Buffer>,
#[builder(setter(custom))]
scope: Object,
#[cfg(feature = "nightly")]
#[cfg_attr(docsrs, doc(cfg(feature = "nightly")))]
#[builder(setter(into, strip_option))]
window: Option<crate::api::Window>,
}
impl OptionValueOpts {
#[inline(always)]
pub fn builder() -> OptionValueOptsBuilder {
OptionValueOptsBuilder::default()
}
}
impl OptionValueOptsBuilder {
pub fn scope(&mut self, scope: OptionScope) -> &mut Self {
self.scope = Some(nvim::String::from(scope).into());
self
}
pub fn build(&mut self) -> OptionValueOpts {
self.fallible_build().expect("never fails, all fields have defaults")
}
}
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, Serialize)]
#[serde(rename_all = "lowercase")]
pub enum OptionScope {
Global,
Local,
}
impl From<OptionScope> for nvim::String {
fn from(ctx: OptionScope) -> Self {
ctx.serialize(object::Serializer)
.expect("`OptionScope` is serializable")
.try_into()
.expect("`OptionScope` is serialized into a string")
}
}
#[derive(Default)]
#[allow(non_camel_case_types)]
#[repr(C)]
pub(crate) struct KeyDict_option<'a> {
#[cfg(feature = "nightly")]
buf: Object,
#[cfg(feature = "nightly")]
win: Object,
scope: NonOwning<'a, Object>,
}
impl<'a> From<&'a OptionValueOpts> for KeyDict_option<'a> {
fn from(opts: &'a OptionValueOpts) -> Self {
Self {
#[cfg(feature = "nightly")]
buf: opts.buffer.into(),
#[cfg(feature = "nightly")]
win: opts.window.into(),
scope: opts.scope.non_owning(),
}
}
}