diff --git a/crates/oxi-api/src/opts/get_option_value.rs b/crates/oxi-api/src/opts/get_option_value.rs index f0402ce9..8d5a1bde 100644 --- a/crates/oxi-api/src/opts/get_option_value.rs +++ b/crates/oxi-api/src/opts/get_option_value.rs @@ -1,46 +1,48 @@ -#[cfg(not(feature = "neovim-nightly"))] -use oxi_types::Object; -use oxi_types::{self as nvim, conversion::FromObject}; -#[cfg(feature = "neovim-nightly")] -use oxi_types::{BufHandle, String as NvimString, WinHandle}; +use oxi_types as types; use serde::Serialize; +use types::conversion::FromObject; use crate::{Buffer, Window}; /// Options passed to /// [`set_option_value()`](crate::set_option_value). -#[cfg(not(feature = "neovim-nightly"))] -#[derive(Clone, Debug, Default)] +#[cfg(feature = "neovim-nightly")] +#[derive(Clone, Debug, Default, oxi_macros::OptsBuilder)] #[repr(C)] pub struct OptionValueOpts { - buf: Object, - win: Object, - scope: Object, - filetype: Object, + #[builder(mask)] + mask: u64, + + #[builder(argtype = "OptionScope", inline = "{0}.into()")] + scope: types::String, + + #[builder(argtype = "Window", inline = "{0}.0")] + win: types::WinHandle, + + #[builder(method = "buffer", argtype = "Buffer", inline = "{0}.0")] + buf: types::BufHandle, + + #[builder( + generics = "F: Into", + argtype = "F", + inline = "{0}.into()" + )] + filetype: types::String, } /// Options passed to /// [`set_option_value()`](crate::set_option_value). -#[cfg(feature = "neovim-nightly")] +#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))] #[derive(Clone, Debug, Default)] #[repr(C)] pub struct OptionValueOpts { - /// 1 - mask: u64, - - /// 3rd in the mask. - scope: NvimString, - - /// 2nd in the mask. - win: WinHandle, - - /// 1st in the mask. - buf: BufHandle, - - /// 4th in the mask. - filetype: NvimString, + buf: types::Object, + win: types::Object, + scope: types::Object, + filetype: types::Object, } +#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))] impl OptionValueOpts { #[inline(always)] pub fn builder() -> OptionValueOptsBuilder { @@ -48,69 +50,35 @@ impl OptionValueOpts { } } +#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))] #[derive(Clone, Default)] pub struct OptionValueOptsBuilder(OptionValueOpts); +#[cfg(any(feature = "neovim-0-8", feature = "neovim-0-9"))] impl OptionValueOptsBuilder { #[inline] pub fn buffer(&mut self, buffer: Buffer) -> &mut Self { - #[cfg(not(feature = "neovim-nightly"))] - { - self.0.buf = buffer.into(); - } - #[cfg(feature = "neovim-nightly")] - { - self.0.buf = buffer.0; - self.0.mask |= 0b11; - } + self.0.buf = buffer.into(); self } #[inline] pub fn filetype(&mut self, filetype: &str) -> &mut Self { - let filetype = nvim::String::from(filetype); - - #[cfg(not(feature = "neovim-nightly"))] - { - self.0.filetype = filetype.into(); - } - #[cfg(feature = "neovim-nightly")] - { - self.0.filetype = filetype; - self.0.mask |= 0b10001; - } - + let filetype = types::String::from(filetype); + self.0.filetype = filetype.into(); self } #[inline] pub fn scope(&mut self, scope: OptionScope) -> &mut Self { - let scope = nvim::String::from(scope); - - #[cfg(not(feature = "neovim-nightly"))] - { - self.0.scope = scope.into(); - } - #[cfg(feature = "neovim-nightly")] - { - self.0.scope = scope; - self.0.mask |= 0b1001; - } - + let scope = types::String::from(scope); + self.0.scope = scope.into(); self } #[inline] pub fn window(&mut self, window: Window) -> &mut Self { - #[cfg(not(feature = "neovim-nightly"))] - { - self.0.win = window.into(); - } - #[cfg(feature = "neovim-nightly")] - { - self.0.win = window.0; - self.0.mask |= 0b101; - } + self.0.win = window.into(); self } @@ -127,11 +95,11 @@ pub enum OptionScope { Local, } -impl From for nvim::String { +impl From for types::String { #[inline] fn from(ctx: OptionScope) -> Self { - nvim::String::from_object( - ctx.serialize(nvim::serde::Serializer::new()) + types::String::from_object( + ctx.serialize(types::serde::Serializer::new()) .expect("`OptionScope` is serializable"), ) .expect("`OptionScope` is serialized into a string")