From 839efcf5c25e3202002e791c6ee1161259d2d760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 13:48:58 +0200 Subject: [PATCH 01/12] chore: Specify the resolver the workspace should use --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 8932603..ba87ace 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,10 +1,10 @@ [workspace] - members = [ "crates/*", ] +resolver = "2" [profile.release] -opt-level = 'z' +opt-level = "z" codegen-units = 1 lto = true From c2a414eab8995b5e10a9bf6d7c783531c6e192a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 13:49:15 +0200 Subject: [PATCH 02/12] ci: Add an initial CI configuration --- .github/workflows/ci.yml | 97 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 .github/workflows/ci.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..3048e7f --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,97 @@ +name: CI + +on: + push: + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + style: + name: Check style + runs-on: ubuntu-latest + + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + + - name: Install rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: rustfmt + + - name: Cargo fmt + run: cargo fmt --all -- --check + + typos: + name: Spell Check with Typos + runs-on: ubuntu-latest + + steps: + - name: Checkout Actions Repository + uses: actions/checkout@v4 + + - name: Check the spelling of the files in our repo + uses: crate-ci/typos@master + + clippy: + name: Run clippy + needs: [style] + runs-on: ubuntu-latest + + steps: + - name: Checkout the repo + uses: actions/checkout@v4 + + - name: Install WeeChat + run: | + sudo apt-get update + sudo apt-get install weechat-dev + + + - name: Install rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: nightly + components: clippy + + - uses: Swatinem/rust-cache@v2 + + - name: Clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + test: + name: ${{ matrix.target.name }} ${{ matrix.channel }} + needs: [clippy] + + runs-on: ${{ matrix.target.os }} + strategy: + matrix: + target: [ + { "os": "ubuntu-latest", "toolchain": "x86_64-unknown-linux-gnu", "name": "Linux GNU" }, + # TODO: Add some more OS variants here. + ] + channel: [stable, beta, nightly] + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install WeeChat + if: runner.os == 'Linux' + run: | + sudo apt-get update + sudo apt-get install weechat-dev + + - name: Install rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ format('{0}-{1}', matrix.channel, matrix.target.toolchain) }} + + - uses: Swatinem/rust-cache@v2 + + - name: Test + run: cargo test --all-features From e438ed61e7cd0cf75359d28dcf9be6027f809ed9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 13:49:31 +0200 Subject: [PATCH 03/12] chore: Add an editorconfig and rust-analyzer settings --- .editorconfig | 17 +++++++++++++++++ .vscode/settings.json | 7 +++++++ 2 files changed, 24 insertions(+) create mode 100644 .editorconfig create mode 100644 .vscode/settings.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..6a51fe4 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,17 @@ +root = true + +[*] +charset = utf-8 + +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true + +indent_style = space +indent_size = 4 + +[*.md] +trim_trailing_whitespace = false + +[*.yml] +indent_size = 2 diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..8d5f789 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,7 @@ +{ + "rust-analyzer.checkOnSave.command": "clippy", + "rust-analyzer.cargo.features": "all", + "rust-analyzer.rustfmt": { + "extraArgs": ["+nightly"] + } +} From 0e60bd074d956ffaa42cf716c2a061587a9b45fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 13:34:20 +0200 Subject: [PATCH 04/12] chore: Fix all the clippy warnings we have --- crates/weechat-macro/src/lib.rs | 4 ++- crates/weechat/src/buffer/mod.rs | 23 ++++++------ crates/weechat/src/buffer/window.rs | 2 +- crates/weechat/src/config/boolean.rs | 6 ++-- crates/weechat/src/config/color.rs | 6 ++-- crates/weechat/src/config/config.rs | 21 +++++------ crates/weechat/src/config/config_options.rs | 5 +-- crates/weechat/src/config/enum.rs | 9 +++-- crates/weechat/src/config/integer.rs | 6 ++-- crates/weechat/src/config/section.rs | 40 ++++++++++----------- crates/weechat/src/config/string.rs | 9 ++--- crates/weechat/src/config_macros.rs | 1 - crates/weechat/src/executor.rs | 8 ++--- crates/weechat/src/hooks/bar.rs | 4 +-- crates/weechat/src/hooks/completion.rs | 4 +-- crates/weechat/src/hooks/fd.rs | 6 ++-- crates/weechat/src/hooks/modifier.rs | 8 ++--- crates/weechat/src/hooks/signal.rs | 36 +++++++++---------- crates/weechat/src/infolist.rs | 15 ++++---- crates/weechat/src/lib.rs | 3 +- crates/weechat/src/weechat.rs | 14 ++++---- 21 files changed, 112 insertions(+), 118 deletions(-) diff --git a/crates/weechat-macro/src/lib.rs b/crates/weechat-macro/src/lib.rs index f5e0272..6d5ea1b 100644 --- a/crates/weechat-macro/src/lib.rs +++ b/crates/weechat-macro/src/lib.rs @@ -197,7 +197,9 @@ pub fn plugin(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let weechat = unsafe { Weechat::init_from_ptr(plugin) }; - let args = Args::new(argc, argv); + + let args = unsafe { Args::new(argc, argv) }; + match <#plugin as ::weechat::Plugin>::init(&weechat, args) { Ok(p) => { unsafe { diff --git a/crates/weechat/src/buffer/mod.rs b/crates/weechat/src/buffer/mod.rs index 7b17403..e878773 100644 --- a/crates/weechat/src/buffer/mod.rs +++ b/crates/weechat/src/buffer/mod.rs @@ -69,7 +69,7 @@ impl<'a> InnerBuffers<'a> { impl<'a> InnerBuffers<'a> { pub(crate) fn weechat(&self) -> &Weechat { match self { - InnerBuffers::BorrowedBuffer(b) => &b.weechat, + InnerBuffers::BorrowedBuffer(b) => b.weechat, InnerBuffers::OwnedBuffer(b) => &b.weechat, } } @@ -95,7 +95,7 @@ impl PartialEq for Buffer<'_> { impl PartialOrd for Buffer<'_> { fn partial_cmp(&self, other: &Buffer) -> Option { - self.number().partial_cmp(&other.number()) + Some(self.number().cmp(&other.number())) } } @@ -220,7 +220,6 @@ impl Result<(), ()> + 'static> BufferCloseCallbac } #[cfg(feature = "async")] -#[cfg_attr(feature = "docs", doc(cfg(r#async)))] #[async_trait(?Send)] /// Trait for the buffer input callback. /// @@ -253,7 +252,6 @@ impl LocalBoxFuture<'static, ()> + 'static> } #[cfg(feature = "async")] -#[cfg_attr(feature = "docs", doc(cfg(r#async)))] /// Builder for the creation of a buffer. pub struct BufferBuilderAsync { pub(crate) name: String, @@ -276,7 +274,7 @@ impl BufferBuilderAsync { /// # Arguments /// /// * `name` - The name of the new buffer. Needs to be unique across a - /// plugin, otherwise the buffer creation will fail. + /// plugin, otherwise the buffer creation will fail. /// /// Returns a Buffer if one has been created, otherwise an empty Error. /// @@ -350,7 +348,7 @@ impl BufferBuilder { /// # Arguments /// /// * `name` - The name of the new buffer. Needs to be unique across a - /// plugin, otherwise the buffer creation will fail. + /// plugin, otherwise the buffer creation will fail. /// /// # Panics /// @@ -392,7 +390,7 @@ impl BufferBuilder { /// # Arguments /// /// * `callback` - A function or a struct that implements the - /// BufferCloseCallback trait. + /// BufferCloseCallback trait. pub fn input_callback(mut self, callback: impl BufferInputCallback + 'static) -> Self { self.input_callback = Some(Box::new(callback)); self @@ -478,7 +476,6 @@ impl Weechat { } #[cfg(feature = "async")] - #[cfg_attr(feature = "docs", doc(cfg(r#async)))] fn buffer_new_with_async(builder: BufferBuilderAsync) -> Result { unsafe extern "C" fn c_input_cb( pointer: *const c_void, @@ -582,7 +579,7 @@ impl Weechat { }; if buf_ptr.is_null() { - unsafe { Box::from_raw(buffer_pointers_ref) }; + unsafe { drop(Box::from_raw(buffer_pointers_ref)) }; return Err(()); } @@ -697,7 +694,7 @@ impl Weechat { }; if buf_ptr.is_null() { - unsafe { Box::from_raw(buffer_pointers_ref) }; + unsafe { drop(Box::from_raw(buffer_pointers_ref)) }; return Err(()); } @@ -728,7 +725,7 @@ pub(crate) type WeechatInputCbT = unsafe extern "C" fn( impl Buffer<'_> { fn weechat(&self) -> &Weechat { match &self.inner { - InnerBuffers::BorrowedBuffer(b) => &b.weechat, + InnerBuffers::BorrowedBuffer(b) => b.weechat, InnerBuffers::OwnedBuffer(b) => &b.weechat, } } @@ -830,7 +827,7 @@ impl Buffer<'_> { /// Returns a `Nick` if one is found, None otherwise. pub fn search_nick(&self, nick: &str) -> Option { let weechat = self.weechat(); - let nick = Buffer::search_nick_helper(&weechat, self.ptr(), nick, None); + let nick = Buffer::search_nick_helper(weechat, self.ptr(), nick, None); if nick.is_null() { None @@ -871,7 +868,7 @@ impl Buffer<'_> { /// error otherwise. pub fn add_nick(&self, nick_settings: NickSettings) -> Result { let weechat = self.weechat(); - let nick_ptr = Buffer::add_nick_helper(&weechat, self.ptr(), nick_settings, None); + let nick_ptr = Buffer::add_nick_helper(weechat, self.ptr(), nick_settings, None); if nick_ptr.is_null() { return Err(()); diff --git a/crates/weechat/src/buffer/window.rs b/crates/weechat/src/buffer/window.rs index d96f5a7..f75cc05 100644 --- a/crates/weechat/src/buffer/window.rs +++ b/crates/weechat/src/buffer/window.rs @@ -130,7 +130,7 @@ impl<'a> Window<'a> { /// # Arguments /// /// * `title` - The new title that should be set for the terminal, the - /// string is evaluated, so variables like ${info:version} can be used. + /// string is evaluated, so variables like ${info:version} can be used. pub fn set_title(&self, title: &str) { self.set_title_helper(Some(title)); } diff --git a/crates/weechat/src/config/boolean.rs b/crates/weechat/src/config/boolean.rs index 749f2a5..14b43ca 100644 --- a/crates/weechat/src/config/boolean.rs +++ b/crates/weechat/src/config/boolean.rs @@ -10,6 +10,8 @@ use crate::{ Weechat, }; +type BooleanChangeCallback = Box; + /// Settings for a new boolean option. #[derive(Default)] pub struct BooleanOptionSettings { @@ -19,7 +21,7 @@ pub struct BooleanOptionSettings { pub(crate) default_value: bool, - pub(crate) change_cb: Option>, + pub(crate) change_cb: Option, } impl BooleanOptionSettings { @@ -114,7 +116,7 @@ impl<'a> HiddenConfigOptionT for BooleanOption<'a> { } impl<'a> BaseConfigOption for BooleanOption<'a> {} -impl<'a> ConfigOptions for BooleanOption<'_> {} +impl<'a> ConfigOptions for BooleanOption<'a> {} impl<'a> PartialEq for BooleanOption<'a> { fn eq(&self, other: &bool) -> bool { diff --git a/crates/weechat/src/config/color.rs b/crates/weechat/src/config/color.rs index eced8ab..088b08a 100644 --- a/crates/weechat/src/config/color.rs +++ b/crates/weechat/src/config/color.rs @@ -10,6 +10,8 @@ use crate::{ Weechat, }; +type ColorChangeCallback = Box; + /// Settings for a new color option. #[derive(Default)] pub struct ColorOptionSettings { @@ -19,7 +21,7 @@ pub struct ColorOptionSettings { pub(crate) default_value: String, - pub(crate) change_cb: Option>, + pub(crate) change_cb: Option, } impl ColorOptionSettings { @@ -115,4 +117,4 @@ impl<'a> HiddenConfigOptionT for ColorOption<'a> { } impl<'a> BaseConfigOption for ColorOption<'a> {} -impl<'a> ConfigOptions for ColorOption<'_> {} +impl<'a> ConfigOptions for ColorOption<'a> {} diff --git a/crates/weechat/src/config/config.rs b/crates/weechat/src/config/config.rs index c690e17..a5452fd 100644 --- a/crates/weechat/src/config/config.rs +++ b/crates/weechat/src/config/config.rs @@ -120,8 +120,7 @@ impl Weechat { /// # Arguments /// /// * `option_name` - The full name of the option that should be searched - /// for - /// (format: "file.section.option"). + /// for (format: "file.section.option"). pub fn config_get(&self, option_name: &str) -> Option { let weechat = Weechat::from_ptr(self.ptr); let config_get = weechat.get().config_get.unwrap(); @@ -164,7 +163,7 @@ impl Weechat { unsafe { let result = config_set_plugin(self.ptr, option_name.as_ptr(), value.as_ptr()); - OptionChanged::from_int(result as i32) + OptionChanged::from_int(result) } } } @@ -179,7 +178,7 @@ impl Drop for Config { unsafe { // Now drop the config. - Box::from_raw(self._config_data); + drop(Box::from_raw(self._config_data)); config_free(self.inner.ptr) }; } @@ -207,7 +206,7 @@ impl Config { /// * `name` - Name of the new configuration file /// /// * `reload_callback` - Callback that will be called when the - /// configuration file is reloaded. + /// configuration file is reloaded. /// /// # Examples /// @@ -261,11 +260,7 @@ impl Config { let weechat = unsafe { Weechat::weechat() }; let c_name = LossyCString::new(name); - - let c_reload_cb = match callback { - Some(_) => Some(c_reload_cb as ReloadCB), - None => None, - }; + let c_reload_cb = callback.as_ref().map(|_| c_reload_cb as ReloadCB); let config_pointers = Box::new(ConfigPointers { reload_cb: callback, weechat_ptr: weechat.ptr }); @@ -284,7 +279,7 @@ impl Config { }; if config_ptr.is_null() { - unsafe { Box::from_raw(config_pointers_ref) }; + unsafe { drop(Box::from_raw(config_pointers_ref)) }; return Err(()); }; @@ -367,7 +362,7 @@ impl Config { /// # Arguments /// /// * `section_settings` - Settings that decide how the section will be - /// created. + /// created. /// /// # Panics /// @@ -518,7 +513,7 @@ impl Config { }; if ptr.is_null() { - unsafe { Box::from_raw(section_data_ptr) }; + unsafe { drop(Box::from_raw(section_data_ptr)) }; return Err(()); }; diff --git a/crates/weechat/src/config/config_options.rs b/crates/weechat/src/config/config_options.rs index 93af708..58de187 100644 --- a/crates/weechat/src/config/config_options.rs +++ b/crates/weechat/src/config/config_options.rs @@ -143,10 +143,11 @@ pub trait BaseConfigOption: HiddenConfigOptionT { pub trait ConfigOptions: BaseConfigOption + FromPtrs {} pub(crate) type CheckCB = dyn FnMut(&Weechat, &T, Cow) -> bool; +pub(crate) type OptionCallback = Box; pub(crate) struct OptionPointers { pub(crate) weechat_ptr: *mut t_weechat_plugin, pub(crate) check_cb: Option>>, - pub(crate) change_cb: Option>, - pub(crate) delete_cb: Option>, + pub(crate) change_cb: Option>, + pub(crate) delete_cb: Option>, } diff --git a/crates/weechat/src/config/enum.rs b/crates/weechat/src/config/enum.rs index 087f988..eecbdd3 100644 --- a/crates/weechat/src/config/enum.rs +++ b/crates/weechat/src/config/enum.rs @@ -10,6 +10,8 @@ use crate::{ Weechat, }; +type EnumChangeCallback = Box; + /// Settings for a new enum option. #[derive(Default)] pub struct EnumOptionSettings { @@ -25,13 +27,14 @@ pub struct EnumOptionSettings { pub(crate) string_values: String, - pub(crate) change_cb: Option>, + pub(crate) change_cb: Option, } impl EnumOptionSettings { /// Create new settings that can be used to create a new enum option. /// - /// An enum option is represented as integer (index of enum value) internally + /// An enum option is represented as integer (index of enum value) + /// internally /// /// # Arguments /// @@ -164,4 +167,4 @@ impl<'a> HiddenConfigOptionT for EnumOption<'a> { } impl<'a> BaseConfigOption for EnumOption<'a> {} -impl<'a> ConfigOptions for EnumOption<'_> {} +impl<'a> ConfigOptions for EnumOption<'a> {} diff --git a/crates/weechat/src/config/integer.rs b/crates/weechat/src/config/integer.rs index 64ca17f..04ab8b5 100644 --- a/crates/weechat/src/config/integer.rs +++ b/crates/weechat/src/config/integer.rs @@ -10,6 +10,8 @@ use crate::{ Weechat, }; +type IntegerOptionCallback = Box; + /// Settings for a new integer option. #[derive(Default)] pub struct IntegerOptionSettings { @@ -23,7 +25,7 @@ pub struct IntegerOptionSettings { pub(crate) max: i32, - pub(crate) change_cb: Option>, + pub(crate) change_cb: Option, } impl IntegerOptionSettings { @@ -139,4 +141,4 @@ impl<'a> HiddenConfigOptionT for IntegerOption<'a> { } impl<'a> BaseConfigOption for IntegerOption<'a> {} -impl<'a> ConfigOptions for IntegerOption<'_> {} +impl<'a> ConfigOptions for IntegerOption<'a> {} diff --git a/crates/weechat/src/config/section.rs b/crates/weechat/src/config/section.rs index 3f00720..d24cf4d 100644 --- a/crates/weechat/src/config/section.rs +++ b/crates/weechat/src/config/section.rs @@ -11,6 +11,7 @@ use std::{ use weechat_sys::{t_config_file, t_config_option, t_config_section, t_weechat_plugin}; +use super::config_options::OptionCallback; use crate::{ config::{ config_options::{CheckCB, OptionPointers, OptionType}, @@ -127,7 +128,7 @@ impl<'a> Deref for SectionHandle<'a> { type Target = ConfigSection; fn deref(&self) -> &Self::Target { - &*self.inner + &self.inner } } @@ -135,13 +136,13 @@ impl<'a> Deref for SectionHandleMut<'a> { type Target = ConfigSection; fn deref(&self) -> &Self::Target { - &*self.inner + &self.inner } } impl<'a> DerefMut for SectionHandleMut<'a> { fn deref_mut(&mut self) -> &mut Self::Target { - &mut *self.inner + &mut self.inner } } @@ -170,8 +171,8 @@ pub trait SectionWriteCallback: 'static { /// * `config` - A borrowed version of the Weechat configuration object. /// /// * `section` - The section that is being written, if the Config struct is - /// contained inside of `self` make sure not to borrow the same section - /// again. + /// contained inside of `self` make sure not to borrow the same section + /// again. fn callback(&mut self, weechat: &Weechat, config: &Conf, section: &mut ConfigSection); } @@ -196,8 +197,8 @@ pub trait SectionWriteDefaultCallback: 'static { /// * `config` - A borrowed version of the Weechat configuration object. /// /// * `section` - The section that is being populated with default values, - /// if the Config struct is contained inside of `self` make sure not to - /// borrow the same section again. + /// if the Config struct is contained inside of `self` make sure not to + /// borrow the same section again. fn callback(&mut self, weechat: &Weechat, config: &Conf, section: &mut ConfigSection); } @@ -223,8 +224,8 @@ pub trait SectionReadCallback: 'static { /// * `config` - A borrowed version of the Weechat configuration object. /// /// * `section` - The section that is being populated with default values, - /// if the Config struct is contained inside of `self` make sure not to - /// borrow the same section again. + /// if the Config struct is contained inside of `self` make sure not to + /// borrow the same section again. /// /// * `option_name` - The name of the option that is currently being read. /// @@ -373,26 +374,26 @@ impl Drop for ConfigSection { unsafe { match option_ptrs { ConfigOptionPointers::Integer(p) => { - Box::from_raw(p as *mut OptionPointers); + drop(Box::from_raw(p as *mut OptionPointers)); } ConfigOptionPointers::Boolean(p) => { - Box::from_raw(p as *mut OptionPointers); + drop(Box::from_raw(p as *mut OptionPointers)); } ConfigOptionPointers::String(p) => { - Box::from_raw(p as *mut OptionPointers); + drop(Box::from_raw(p as *mut OptionPointers)); } ConfigOptionPointers::Color(p) => { - Box::from_raw(p as *mut OptionPointers); + drop(Box::from_raw(p as *mut OptionPointers)); } ConfigOptionPointers::Enum(p) => { - Box::from_raw(p as *mut OptionPointers); + drop(Box::from_raw(p as *mut OptionPointers)); } } } } unsafe { - Box::from_raw(self.section_data as *mut ConfigSectionPointers); + drop(Box::from_raw(self.section_data as *mut ConfigSectionPointers)); options_free(self.ptr); section_free(self.ptr); }; @@ -684,8 +685,8 @@ impl ConfigSection { &self, option_description: OptionDescription, check_cb: Option>>, - change_cb: Option>, - delete_cb: Option>, + change_cb: Option>, + delete_cb: Option>, ) -> Option<(*mut t_config_option, *const c_void)> where T: ConfigOptions, @@ -757,10 +758,7 @@ impl ConfigSection { let default_value = LossyCString::new(option_description.default_value); let value = LossyCString::new(option_description.value); - let c_check_cb = match check_cb { - Some(_) => Some(c_check_cb:: as WeechatOptCheckCbT), - None => None, - }; + let c_check_cb = check_cb.as_ref().map(|_| c_check_cb:: as WeechatOptCheckCbT); let c_change_cb: Option = match change_cb { Some(_) => Some(c_change_cb::), diff --git a/crates/weechat/src/config/string.rs b/crates/weechat/src/config/string.rs index c7656ed..bbbbb8a 100644 --- a/crates/weechat/src/config/string.rs +++ b/crates/weechat/src/config/string.rs @@ -10,7 +10,8 @@ use crate::{ Weechat, }; -type StringCheckCb = Option) -> bool>>; +type StringCheckCb = Box) -> bool>; +type StringChangeCallback = Box; /// Settings for a new string option. #[derive(Default)] @@ -21,9 +22,9 @@ pub struct StringOptionSettings { pub(crate) default_value: String, - pub(crate) change_cb: Option>, + pub(crate) change_cb: Option, - pub(crate) check_cb: StringCheckCb, + pub(crate) check_cb: Option, } impl StringOptionSettings { @@ -143,4 +144,4 @@ impl<'a> HiddenConfigOptionT for StringOption<'a> { } impl<'a> BaseConfigOption for StringOption<'a> {} -impl<'a> ConfigOptions for StringOption<'_> {} +impl<'a> ConfigOptions for StringOption<'a> {} diff --git a/crates/weechat/src/config_macros.rs b/crates/weechat/src/config_macros.rs index 0922591..f0d7187 100644 --- a/crates/weechat/src/config_macros.rs +++ b/crates/weechat/src/config_macros.rs @@ -304,7 +304,6 @@ macro_rules! section_getter { /// ); /// ``` #[cfg(feature = "config_macro")] -#[cfg_attr(feature = "docs", doc(cfg(config_macro)))] #[macro_export] macro_rules! config { ($config_name:literal, $(Section $section:ident { $($option:tt)* }), * $(,)?) => { diff --git a/crates/weechat/src/executor.rs b/crates/weechat/src/executor.rs index 9e6751f..2b75b65 100644 --- a/crates/weechat/src/executor.rs +++ b/crates/weechat/src/executor.rs @@ -96,6 +96,7 @@ impl WeechatExecutor { let non_local = Arc::new(Mutex::new(VecDeque::new())); let executor = WeechatExecutor { + #[allow(clippy::arc_with_non_send_sync)] _hook: Arc::new(Mutex::new(None)), sender, futures: queue, @@ -180,12 +181,7 @@ impl WeechatExecutor { F::Output: 'static, { let executor = unsafe { _EXECUTOR.as_ref() }; - - if let Some(executor) = executor { - Some(executor.spawn_local(future)) - } else { - None - } + executor.map(|executor| executor.spawn_local(future)) } pub(crate) fn spawn_buffer_cb(buffer_name: String, future: F) -> Task diff --git a/crates/weechat/src/hooks/bar.rs b/crates/weechat/src/hooks/bar.rs index 6318398..868966c 100644 --- a/crates/weechat/src/hooks/bar.rs +++ b/crates/weechat/src/hooks/bar.rs @@ -60,8 +60,8 @@ impl BarItem { /// /// * `name` - The name of the new bar item. /// - /// * `callback` - The callback that should be called after the bar items - /// is marked to be updated. + /// * `callback` - The callback that should be called after the bar items is + /// marked to be updated. /// /// # Panics /// diff --git a/crates/weechat/src/hooks/completion.rs b/crates/weechat/src/hooks/completion.rs index 381912d..caf06cb 100644 --- a/crates/weechat/src/hooks/completion.rs +++ b/crates/weechat/src/hooks/completion.rs @@ -24,12 +24,12 @@ pub trait CompletionCallback { /// * `weechat` - A Weechat context. /// /// * `buffer` - The currently active buffer that requested the completion - /// to run. + /// to run. /// /// * `completion_name` - The name of the completion. /// /// * `completion` - The completion object that should be populated with - /// completion words by the callback. + /// completion words by the callback. fn callback( &mut self, weechat: &Weechat, diff --git a/crates/weechat/src/hooks/fd.rs b/crates/weechat/src/hooks/fd.rs index 02d20f0..d7003dd 100644 --- a/crates/weechat/src/hooks/fd.rs +++ b/crates/weechat/src/hooks/fd.rs @@ -90,7 +90,7 @@ impl FdHook { /// # Example /// /// ```no_run - /// + /// /// # use weechat::{Weechat, hooks::{FdHook, FdHookMode, FdHookCallback}}; /// # use pipe_channel::{channel, Receiver, Sender}; /// @@ -126,10 +126,10 @@ impl FdHook { ) -> c_int { let hook_data: &mut FdHookData = { &mut *(pointer as *mut FdHookData) }; let cb = &mut hook_data.callback; - let mut fd_object = &mut hook_data.fd_object; + let fd_object = &mut hook_data.fd_object; let weechat = Weechat::from_ptr(hook_data.weechat_ptr); - cb.callback(&weechat, &mut fd_object); + cb.callback(&weechat, fd_object); WEECHAT_RC_OK } diff --git a/crates/weechat/src/hooks/modifier.rs b/crates/weechat/src/hooks/modifier.rs index 641b03b..b5f1511 100644 --- a/crates/weechat/src/hooks/modifier.rs +++ b/crates/weechat/src/hooks/modifier.rs @@ -7,7 +7,7 @@ use super::Hook; use crate::{buffer::Buffer, LossyCString, Weechat}; /// Hook for a modifier, the hook is removed when the object is dropped. -#[cfg_attr(feature = "docs", doc(cfg(unsound)))] +#[cfg_attr(docsrs, doc(cfg(unsound)))] pub struct ModifierHook { _hook: Hook, _hook_data: Box, @@ -131,8 +131,8 @@ impl ModifierHook { /// * `modifier_name` - The modifier to hook. /// /// * `callback` - A function or a struct that implements ModifierCallback, - /// the callback method of the trait will be called when the modifier is - /// fired. + /// the callback method of the trait will be called when the modifier is + /// fired. /// /// # Panics /// @@ -158,7 +158,7 @@ impl ModifierHook { /// None /// }); /// ``` - #[cfg_attr(feature = "docs", doc(cfg(unsound)))] + #[cfg_attr(docsrs, doc(cfg(unsound)))] pub fn new(modifier_name: &str, callback: impl ModifierCallback + 'static) -> Result { unsafe extern "C" fn c_hook_cb( pointer: *const c_void, diff --git a/crates/weechat/src/hooks/signal.rs b/crates/weechat/src/hooks/signal.rs index 8f1e6e9..fd80a01 100644 --- a/crates/weechat/src/hooks/signal.rs +++ b/crates/weechat/src/hooks/signal.rs @@ -37,38 +37,38 @@ pub enum SignalData<'a> { Buffer(Buffer<'a>), } -impl<'a> Into> for &'a str { - fn into(self) -> SignalData<'a> { - SignalData::String(Cow::from(self)) +impl<'a> From<&'a str> for SignalData<'a> { + fn from(string: &'a str) -> SignalData<'a> { + SignalData::String(Cow::from(string)) } } -impl<'a> Into> for String { - fn into(self) -> SignalData<'a> { - SignalData::String(Cow::from(self)) +impl<'a> From for SignalData<'a> { + fn from(val: String) -> Self { + SignalData::String(Cow::from(val)) } } -impl<'a> Into> for i32 { - fn into(self) -> SignalData<'a> { - SignalData::Integer(self) +impl<'a> From for SignalData<'a> { + fn from(val: i32) -> Self { + SignalData::Integer(val) } } -impl<'a> Into> for Buffer<'a> { - fn into(self) -> SignalData<'a> { - SignalData::Buffer(self) +impl<'a> From> for SignalData<'a> { + fn from(val: Buffer<'a>) -> Self { + SignalData::Buffer(val) } } -impl<'a> Into> for &'a Buffer<'a> { - fn into(self) -> SignalData<'a> { - let ptr = self.ptr(); +impl<'a> From<&'a Buffer<'a>> for SignalData<'a> { + fn from(val: &'a Buffer<'a>) -> Self { + let ptr = val.ptr(); SignalData::Buffer(Buffer { inner: InnerBuffers::BorrowedBuffer(InnerBuffer { ptr, - weechat: self.inner.weechat(), + weechat: val.inner.weechat(), closing: Rc::new(Cell::new(false)), }), }) @@ -197,8 +197,8 @@ impl SignalHook { /// * `signal_name` - The signal to hook (wildcard `*` is allowed). /// /// * `callback` - A function or a struct that implements SignalCallback, - /// the callback method of the trait will be called when the signal is - /// fired. + /// the callback method of the trait will be called when the signal is + /// fired. /// /// # Panics /// diff --git a/crates/weechat/src/infolist.rs b/crates/weechat/src/infolist.rs index 1766dfb..cfec14d 100644 --- a/crates/weechat/src/infolist.rs +++ b/crates/weechat/src/infolist.rs @@ -186,7 +186,7 @@ impl<'a> InfolistItem<'a> { /// } /// ``` pub fn iter(&'a self) -> Iter<'a> { - Iter { keys: self.fields.clone().into_iter(), item: &self } + Iter { keys: self.fields.clone().into_iter(), item: self } } } @@ -305,12 +305,12 @@ impl Weechat { /// # Arguments /// /// * `infolist_name` - The name of the infolist to fetch, valid values for - /// this can be found in the Weechat documentation. + /// this can be found in the Weechat documentation. /// /// * `arguments` - Arguments that should be passed to Weechat while - /// fetching the infolist, the format of this will depend on the infolist - /// that is being fetched. A list of infolists and their accompanying - /// arguments can be found in the Weechat documentation. + /// fetching the infolist, the format of this will depend on the infolist + /// that is being fetched. A list of infolists and their accompanying + /// arguments can be found in the Weechat documentation. /// /// # Example /// @@ -339,8 +339,7 @@ impl Weechat { let infolist_get = self.get().infolist_get.unwrap(); let name = LossyCString::new(infolist_name); - let arguments = - if let Some(args) = arguments { Some(LossyCString::new(args)) } else { None }; + let arguments = arguments.map(LossyCString::new); let infolist_ptr = unsafe { infolist_get( @@ -357,7 +356,7 @@ impl Weechat { Ok(Infolist { ptr: infolist_ptr, infolist_name: infolist_name.to_owned(), - weechat: &self, + weechat: self, }) } } diff --git a/crates/weechat/src/lib.rs b/crates/weechat/src/lib.rs index 04ff5c7..c12323d 100644 --- a/crates/weechat/src/lib.rs +++ b/crates/weechat/src/lib.rs @@ -37,7 +37,7 @@ #![deny(missing_docs)] #![allow(clippy::result_unit_err)] -#![cfg_attr(feature = "docs", feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_auto_cfg))] use std::ffi::CString; @@ -88,7 +88,6 @@ pub trait Plugin: Sized { } #[cfg(feature = "async")] -#[cfg_attr(feature = "docs", doc(cfg(r#async)))] pub use executor::Task; /// Status values for Weechat callbacks diff --git a/crates/weechat/src/weechat.rs b/crates/weechat/src/weechat.rs index e339338..e35a0b9 100644 --- a/crates/weechat/src/weechat.rs +++ b/crates/weechat/src/weechat.rs @@ -63,13 +63,13 @@ impl Args { /// needs to be public because it's used in the macro expansion of the /// plugin init method. #[doc(hidden)] - pub fn new(argc: c_int, argv: *mut *mut c_char) -> Args { + pub unsafe fn new(argc: c_int, argv: *mut *mut c_char) -> Args { let argc = argc as isize; let args: Vec = (0..argc) .map(|i| { let cstr = unsafe { CStr::from_ptr(*argv.offset(i) as *const libc::c_char) }; - String::from_utf8_lossy(&cstr.to_bytes().to_vec()).to_string() + String::from_utf8_lossy(cstr.to_bytes()).to_string() }) .collect(); Args { iter: args.into_iter() } @@ -235,6 +235,7 @@ impl Weechat { /// /// Since this one will have a static lifetime, objects that are fetched /// from this object may have a longer lifetime than they should. + #[allow(clippy::self_named_constructors)] pub unsafe fn weechat() -> &'static mut Weechat { match WEECHAT { Some(ref mut w) => w, @@ -526,11 +527,11 @@ impl Weechat { /// /// * `modifier` - The name of a modifier. The list of modifiers can be /// found in the official - /// [Weechat documentation](https://weechat.org/files/doc/stable/weechat_plugin_api.en.html#_hook_modifier_exec). + /// [Weechat documentation](https://weechat.org/files/doc/stable/weechat_plugin_api.en.html#_hook_modifier_exec). /// /// * `modifier_data` - Data that will be passed to the modifier, this - /// depends on the modifier that was chosen, consult the list of modifiers - /// in the Weechat documentation. + /// depends on the modifier that was chosen, consult the list of modifiers + /// in the Weechat documentation. /// /// * `input_string` - The string that should be modified. /// @@ -619,7 +620,6 @@ impl Weechat { /// block_on(tx.send("Hello world".to_string())); /// ``` #[cfg(feature = "async")] - #[cfg_attr(feature = "docs", doc(cfg(r#async)))] pub fn spawn(future: F) -> Task where F: Future + 'static, @@ -666,7 +666,6 @@ impl Weechat { /// } /// ``` #[cfg(feature = "async")] - #[cfg_attr(feature = "docs", doc(cfg(r#async)))] pub fn spawn_checked(future: F) -> Option> where F: Future + 'static, @@ -681,7 +680,6 @@ impl Weechat { /// This can be called from any thread and will execute the future on the /// main Weechat thread. #[cfg(feature = "async")] - #[cfg_attr(feature = "docs", doc(cfg(r#async)))] pub fn spawn_from_thread(future: F) where F: Future + Send + 'static, From 5484054e0cd57a68974fcef96b27af1b89c5b9f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 13:52:38 +0200 Subject: [PATCH 05/12] chore: Fix a style issue --- crates/weechat/src/hooks/fd.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/crates/weechat/src/hooks/fd.rs b/crates/weechat/src/hooks/fd.rs index d7003dd..10e1d1a 100644 --- a/crates/weechat/src/hooks/fd.rs +++ b/crates/weechat/src/hooks/fd.rs @@ -90,7 +90,6 @@ impl FdHook { /// # Example /// /// ```no_run - /// /// # use weechat::{Weechat, hooks::{FdHook, FdHookMode, FdHookCallback}}; /// # use pipe_channel::{channel, Receiver, Sender}; /// From 485998e493929b7696bf13fa9a8766c66593c5f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 13:59:05 +0200 Subject: [PATCH 06/12] chore: Fix more clippy warnings --- crates/weechat/src/infolist.rs | 2 +- crates/weechat/src/weechat.rs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/crates/weechat/src/infolist.rs b/crates/weechat/src/infolist.rs index cfec14d..c3164dc 100644 --- a/crates/weechat/src/infolist.rs +++ b/crates/weechat/src/infolist.rs @@ -97,7 +97,7 @@ impl<'a> InfolistItem<'a> { unsafe { infolist_integer(self.ptr, name.as_ptr()) } } - fn string(&'a self, name: &str) -> Option> { + fn string(&self, name: &str) -> Option> { let name = LossyCString::new(name); let infolist_string = self.weechat.get().infolist_string.unwrap(); diff --git a/crates/weechat/src/weechat.rs b/crates/weechat/src/weechat.rs index e35a0b9..b43c784 100644 --- a/crates/weechat/src/weechat.rs +++ b/crates/weechat/src/weechat.rs @@ -4,7 +4,7 @@ use std::future::Future; use std::{ ffi::{CStr, CString}, - panic::PanicInfo, + panic::PanicHookInfo, path::PathBuf, ptr, vec, }; @@ -139,7 +139,7 @@ impl Weechat { Weechat { ptr } } - fn panic_hook(info: &PanicInfo) { + fn panic_hook(info: &PanicHookInfo) { let current_thread = std::thread::current(); let weechat_thread = Weechat::thread_id(); @@ -287,6 +287,7 @@ impl Weechat { fn thread_id() -> std::thread::ThreadId { *unsafe { + #[allow(static_mut_refs)] WEECHAT_THREAD_ID.as_ref().expect( "Weechat main thread ID wasn't found, plugin \ wasn't correctly initialized", @@ -295,6 +296,7 @@ impl Weechat { } pub(crate) fn check_thread() { + #[allow(static_mut_refs)] let weechat_thread_id = unsafe { WEECHAT_THREAD_ID.as_ref().expect( "Weechat main thread ID wasn't found, plugin \ From 4e78aa979cf2d13b9a3a5600158e7eecc276b2f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 14:21:07 +0200 Subject: [PATCH 07/12] ci: Install a more recent version of WeeChat --- .github/workflows/ci.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3048e7f..d1319c3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -48,10 +48,15 @@ jobs: - name: Install WeeChat run: | + sudo mkdir /root/.gnupg + sudo chmod 700 /root/.gnupg + sudo mkdir -p /usr/share/keyrings + sudo gpg --no-default-keyring --keyring /usr/share/keyrings/weechat-archive-keyring.gpg --keyserver hkps://keys.openpgp.org --recv-keys 11E9DE8848F2B65222AA75B8D1820DB22A11534E + echo "deb [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/weechat.list + echo "deb-src [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list.d/weechat.list sudo apt-get update sudo apt-get install weechat-dev - - name: Install rust uses: dtolnay/rust-toolchain@master with: From 4ce59bef43f30ce5d118a64783ffa6a73cbfc86a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 14:27:29 +0200 Subject: [PATCH 08/12] chore: More clippy warnings --- crates/weechat/src/buffer/lines.rs | 2 +- crates/weechat/src/buffer/mod.rs | 6 +++--- crates/weechat/src/buffer/nick.rs | 2 +- crates/weechat/src/buffer/nickgroup.rs | 2 +- crates/weechat/src/buffer/window.rs | 2 +- crates/weechat/src/config/boolean.rs | 12 ++++++------ crates/weechat/src/config/color.rs | 10 +++++----- crates/weechat/src/config/enum.rs | 10 +++++----- crates/weechat/src/config/integer.rs | 10 +++++----- crates/weechat/src/config/section.rs | 6 +++--- crates/weechat/src/config/string.rs | 10 +++++----- crates/weechat/src/hooks/signal.rs | 4 ++-- crates/weechat/src/infolist.rs | 6 +++--- 13 files changed, 41 insertions(+), 41 deletions(-) diff --git a/crates/weechat/src/buffer/lines.rs b/crates/weechat/src/buffer/lines.rs index df2a1e1..deb5d2b 100644 --- a/crates/weechat/src/buffer/lines.rs +++ b/crates/weechat/src/buffer/lines.rs @@ -42,7 +42,7 @@ impl<'a> Iterator for BufferLines<'a> { } } -impl<'a> DoubleEndedIterator for BufferLines<'a> { +impl DoubleEndedIterator for BufferLines<'_> { fn next_back(&mut self) -> Option { if self.done { None diff --git a/crates/weechat/src/buffer/mod.rs b/crates/weechat/src/buffer/mod.rs index e878773..3c6d1f6 100644 --- a/crates/weechat/src/buffer/mod.rs +++ b/crates/weechat/src/buffer/mod.rs @@ -39,7 +39,7 @@ pub struct Buffer<'a> { pub(crate) inner: InnerBuffers<'a>, } -impl<'a> std::fmt::Debug for Buffer<'a> { +impl std::fmt::Debug for Buffer<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("Buffer").field("full_name", &self.full_name()).finish() } @@ -50,7 +50,7 @@ pub(crate) enum InnerBuffers<'a> { OwnedBuffer(InnerOwnedBuffer<'a>), } -impl<'a> InnerBuffers<'a> { +impl InnerBuffers<'_> { fn is_closing(&self) -> bool { match self { InnerBuffers::BorrowedBuffer(b) => b.closing.get(), @@ -66,7 +66,7 @@ impl<'a> InnerBuffers<'a> { } } -impl<'a> InnerBuffers<'a> { +impl InnerBuffers<'_> { pub(crate) fn weechat(&self) -> &Weechat { match self { InnerBuffers::BorrowedBuffer(b) => b.weechat, diff --git a/crates/weechat/src/buffer/nick.rs b/crates/weechat/src/buffer/nick.rs index 0944772..ec091aa 100644 --- a/crates/weechat/src/buffer/nick.rs +++ b/crates/weechat/src/buffer/nick.rs @@ -78,7 +78,7 @@ pub struct Nick<'a> { pub(crate) buffer: PhantomData<&'a Buffer<'a>>, } -impl<'a> Nick<'a> { +impl Nick<'_> { /// Get a Weechat object out of the nick. fn get_weechat(&self) -> Weechat { Weechat::from_ptr(self.weechat_ptr) diff --git a/crates/weechat/src/buffer/nickgroup.rs b/crates/weechat/src/buffer/nickgroup.rs index 3d517af..f7abf5d 100644 --- a/crates/weechat/src/buffer/nickgroup.rs +++ b/crates/weechat/src/buffer/nickgroup.rs @@ -15,7 +15,7 @@ pub struct NickGroup<'a> { pub(crate) buffer: PhantomData<&'a Buffer<'a>>, } -impl<'a> NickGroup<'a> { +impl NickGroup<'_> { fn get_weechat(&self) -> Weechat { Weechat::from_ptr(self.weechat_ptr) } diff --git a/crates/weechat/src/buffer/window.rs b/crates/weechat/src/buffer/window.rs index f75cc05..3870860 100644 --- a/crates/weechat/src/buffer/window.rs +++ b/crates/weechat/src/buffer/window.rs @@ -15,7 +15,7 @@ pub struct Window<'a> { pub(crate) phantom: PhantomData<&'a Buffer<'a>>, } -impl<'a> Window<'a> { +impl Window<'_> { fn get_integer(&self, property: &str) -> i32 { let weechat = Weechat::from_ptr(self.weechat); let get_integer = weechat.get().window_get_integer.unwrap(); diff --git a/crates/weechat/src/config/boolean.rs b/crates/weechat/src/config/boolean.rs index 14b43ca..08767eb 100644 --- a/crates/weechat/src/config/boolean.rs +++ b/crates/weechat/src/config/boolean.rs @@ -89,7 +89,7 @@ pub struct BooleanOption<'a> { pub(crate) _phantom: PhantomData<&'a ConfigSection>, } -impl<'a> BooleanOption<'a> { +impl BooleanOption<'_> { /// Get the value of the option. pub fn value(&self) -> bool { let weechat = self.get_weechat(); @@ -99,13 +99,13 @@ impl<'a> BooleanOption<'a> { } } -impl<'a> FromPtrs for BooleanOption<'a> { +impl FromPtrs for BooleanOption<'_> { fn from_ptrs(option_ptr: *mut t_config_option, weechat_ptr: *mut t_weechat_plugin) -> Self { BooleanOption { ptr: option_ptr, weechat_ptr, _phantom: PhantomData } } } -impl<'a> HiddenConfigOptionT for BooleanOption<'a> { +impl HiddenConfigOptionT for BooleanOption<'_> { fn get_ptr(&self) -> *mut t_config_option { self.ptr } @@ -115,10 +115,10 @@ impl<'a> HiddenConfigOptionT for BooleanOption<'a> { } } -impl<'a> BaseConfigOption for BooleanOption<'a> {} -impl<'a> ConfigOptions for BooleanOption<'a> {} +impl BaseConfigOption for BooleanOption<'_> {} +impl ConfigOptions for BooleanOption<'_> {} -impl<'a> PartialEq for BooleanOption<'a> { +impl PartialEq for BooleanOption<'_> { fn eq(&self, other: &bool) -> bool { self.value() == *other } diff --git a/crates/weechat/src/config/color.rs b/crates/weechat/src/config/color.rs index 088b08a..63d311e 100644 --- a/crates/weechat/src/config/color.rs +++ b/crates/weechat/src/config/color.rs @@ -88,7 +88,7 @@ pub struct ColorOption<'a> { pub(crate) _phantom: PhantomData<&'a ConfigSection>, } -impl<'a> ColorOption<'a> { +impl ColorOption<'_> { /// Get the value of the option. pub fn value(&self) -> Cow { let weechat = self.get_weechat(); @@ -100,13 +100,13 @@ impl<'a> ColorOption<'a> { } } -impl<'a> FromPtrs for ColorOption<'a> { +impl FromPtrs for ColorOption<'_> { fn from_ptrs(option_ptr: *mut t_config_option, weechat_ptr: *mut t_weechat_plugin) -> Self { ColorOption { ptr: option_ptr, weechat_ptr, _phantom: PhantomData } } } -impl<'a> HiddenConfigOptionT for ColorOption<'a> { +impl HiddenConfigOptionT for ColorOption<'_> { fn get_ptr(&self) -> *mut t_config_option { self.ptr } @@ -116,5 +116,5 @@ impl<'a> HiddenConfigOptionT for ColorOption<'a> { } } -impl<'a> BaseConfigOption for ColorOption<'a> {} -impl<'a> ConfigOptions for ColorOption<'a> {} +impl BaseConfigOption for ColorOption<'_> {} +impl ConfigOptions for ColorOption<'_> {} diff --git a/crates/weechat/src/config/enum.rs b/crates/weechat/src/config/enum.rs index eecbdd3..11ae240 100644 --- a/crates/weechat/src/config/enum.rs +++ b/crates/weechat/src/config/enum.rs @@ -141,7 +141,7 @@ pub struct EnumOption<'a> { pub(crate) _phantom: PhantomData<&'a ConfigSection>, } -impl<'a> EnumOption<'a> { +impl EnumOption<'_> { /// Get the value of the option. pub fn value(&self) -> i32 { let weechat = self.get_weechat(); @@ -150,13 +150,13 @@ impl<'a> EnumOption<'a> { } } -impl<'a> FromPtrs for EnumOption<'a> { +impl FromPtrs for EnumOption<'_> { fn from_ptrs(option_ptr: *mut t_config_option, weechat_ptr: *mut t_weechat_plugin) -> Self { EnumOption { ptr: option_ptr, weechat_ptr, _phantom: PhantomData } } } -impl<'a> HiddenConfigOptionT for EnumOption<'a> { +impl HiddenConfigOptionT for EnumOption<'_> { fn get_ptr(&self) -> *mut t_config_option { self.ptr } @@ -166,5 +166,5 @@ impl<'a> HiddenConfigOptionT for EnumOption<'a> { } } -impl<'a> BaseConfigOption for EnumOption<'a> {} -impl<'a> ConfigOptions for EnumOption<'a> {} +impl BaseConfigOption for EnumOption<'_> {} +impl ConfigOptions for EnumOption<'_> {} diff --git a/crates/weechat/src/config/integer.rs b/crates/weechat/src/config/integer.rs index 04ab8b5..b9677a3 100644 --- a/crates/weechat/src/config/integer.rs +++ b/crates/weechat/src/config/integer.rs @@ -115,7 +115,7 @@ pub struct IntegerOption<'a> { pub(crate) _phantom: PhantomData<&'a ConfigSection>, } -impl<'a> IntegerOption<'a> { +impl IntegerOption<'_> { /// Get the value of the option. pub fn value(&self) -> i32 { let weechat = self.get_weechat(); @@ -124,13 +124,13 @@ impl<'a> IntegerOption<'a> { } } -impl<'a> FromPtrs for IntegerOption<'a> { +impl FromPtrs for IntegerOption<'_> { fn from_ptrs(option_ptr: *mut t_config_option, weechat_ptr: *mut t_weechat_plugin) -> Self { IntegerOption { ptr: option_ptr, weechat_ptr, _phantom: PhantomData } } } -impl<'a> HiddenConfigOptionT for IntegerOption<'a> { +impl HiddenConfigOptionT for IntegerOption<'_> { fn get_ptr(&self) -> *mut t_config_option { self.ptr } @@ -140,5 +140,5 @@ impl<'a> HiddenConfigOptionT for IntegerOption<'a> { } } -impl<'a> BaseConfigOption for IntegerOption<'a> {} -impl<'a> ConfigOptions for IntegerOption<'a> {} +impl BaseConfigOption for IntegerOption<'_> {} +impl ConfigOptions for IntegerOption<'_> {} diff --git a/crates/weechat/src/config/section.rs b/crates/weechat/src/config/section.rs index d24cf4d..5430c82 100644 --- a/crates/weechat/src/config/section.rs +++ b/crates/weechat/src/config/section.rs @@ -124,7 +124,7 @@ pub struct SectionHandle<'a> { pub(crate) inner: Ref<'a, ConfigSection>, } -impl<'a> Deref for SectionHandle<'a> { +impl Deref for SectionHandle<'_> { type Target = ConfigSection; fn deref(&self) -> &Self::Target { @@ -132,7 +132,7 @@ impl<'a> Deref for SectionHandle<'a> { } } -impl<'a> Deref for SectionHandleMut<'a> { +impl Deref for SectionHandleMut<'_> { type Target = ConfigSection; fn deref(&self) -> &Self::Target { @@ -140,7 +140,7 @@ impl<'a> Deref for SectionHandleMut<'a> { } } -impl<'a> DerefMut for SectionHandleMut<'a> { +impl DerefMut for SectionHandleMut<'_> { fn deref_mut(&mut self) -> &mut Self::Target { &mut self.inner } diff --git a/crates/weechat/src/config/string.rs b/crates/weechat/src/config/string.rs index bbbbb8a..5cd121a 100644 --- a/crates/weechat/src/config/string.rs +++ b/crates/weechat/src/config/string.rs @@ -115,7 +115,7 @@ pub struct StringOption<'a> { pub(crate) _phantom: PhantomData<&'a ConfigSection>, } -impl<'a> StringOption<'a> { +impl StringOption<'_> { /// Get the value of the option. pub fn value(&self) -> Cow { let weechat = self.get_weechat(); @@ -127,13 +127,13 @@ impl<'a> StringOption<'a> { } } -impl<'a> FromPtrs for StringOption<'a> { +impl FromPtrs for StringOption<'_> { fn from_ptrs(option_ptr: *mut t_config_option, weechat_ptr: *mut t_weechat_plugin) -> Self { StringOption { ptr: option_ptr, weechat_ptr, _phantom: PhantomData } } } -impl<'a> HiddenConfigOptionT for StringOption<'a> { +impl HiddenConfigOptionT for StringOption<'_> { fn get_ptr(&self) -> *mut t_config_option { self.ptr } @@ -143,5 +143,5 @@ impl<'a> HiddenConfigOptionT for StringOption<'a> { } } -impl<'a> BaseConfigOption for StringOption<'a> {} -impl<'a> ConfigOptions for StringOption<'a> {} +impl BaseConfigOption for StringOption<'_> {} +impl ConfigOptions for StringOption<'_> {} diff --git a/crates/weechat/src/hooks/signal.rs b/crates/weechat/src/hooks/signal.rs index fd80a01..f285ffc 100644 --- a/crates/weechat/src/hooks/signal.rs +++ b/crates/weechat/src/hooks/signal.rs @@ -43,13 +43,13 @@ impl<'a> From<&'a str> for SignalData<'a> { } } -impl<'a> From for SignalData<'a> { +impl From for SignalData<'_> { fn from(val: String) -> Self { SignalData::String(Cow::from(val)) } } -impl<'a> From for SignalData<'a> { +impl From for SignalData<'_> { fn from(val: i32) -> Self { SignalData::Integer(val) } diff --git a/crates/weechat/src/infolist.rs b/crates/weechat/src/infolist.rs index c3164dc..9a0d8d3 100644 --- a/crates/weechat/src/infolist.rs +++ b/crates/weechat/src/infolist.rs @@ -82,7 +82,7 @@ pub struct InfolistItem<'a> { infolist: PhantomData<&'a Infolist<'a>>, } -impl<'a> Debug for InfolistItem<'a> { +impl Debug for InfolistItem<'_> { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_map().entries(self.fields.iter()).finish() } @@ -239,7 +239,7 @@ pub enum InfolistVariable<'a> { Buffer(Buffer<'a>), } -impl<'a> Infolist<'a> { +impl Infolist<'_> { fn is_pointer_buffer(infolist_name: &str, variable_name: &str) -> bool { matches!( (infolist_name, variable_name), @@ -291,7 +291,7 @@ impl<'a> Infolist<'a> { } } -impl<'a> Drop for Infolist<'a> { +impl Drop for Infolist<'_> { fn drop(&mut self) { let infolist_free = self.weechat.get().infolist_free.unwrap(); From 9efaf78a90cf6f8304d499145efa24d2e138ee6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 14:28:33 +0200 Subject: [PATCH 09/12] ci: Install a more recent version of WeeChat for the tests as well --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d1319c3..8351afa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -88,6 +88,12 @@ jobs: - name: Install WeeChat if: runner.os == 'Linux' run: | + sudo mkdir /root/.gnupg + sudo chmod 700 /root/.gnupg + sudo mkdir -p /usr/share/keyrings + sudo gpg --no-default-keyring --keyring /usr/share/keyrings/weechat-archive-keyring.gpg --keyserver hkps://keys.openpgp.org --recv-keys 11E9DE8848F2B65222AA75B8D1820DB22A11534E + echo "deb [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee /etc/apt/sources.list.d/weechat.list + echo "deb-src [signed-by=/usr/share/keyrings/weechat-archive-keyring.gpg] https://weechat.org/ubuntu jammy main" | sudo tee -a /etc/apt/sources.list.d/weechat.list sudo apt-get update sudo apt-get install weechat-dev From 7f428b2cbcfc517a2a1ef5466d365439e4a356cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 14:33:53 +0200 Subject: [PATCH 10/12] chore: More clippy fixes --- crates/weechat/src/executor.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/crates/weechat/src/executor.rs b/crates/weechat/src/executor.rs index 2b75b65..5c25058 100644 --- a/crates/weechat/src/executor.rs +++ b/crates/weechat/src/executor.rs @@ -145,12 +145,14 @@ impl WeechatExecutor { pub fn free() { unsafe { + #[allow(static_mut_refs)] _EXECUTOR.take(); } } pub fn start() { let executor = WeechatExecutor::new(); + #[allow(static_mut_refs)] unsafe { _EXECUTOR = Some(executor); } @@ -161,6 +163,7 @@ impl WeechatExecutor { where F: Future + Send + 'static, { + #[allow(static_mut_refs)] let executor = unsafe { _EXECUTOR.as_ref().expect("Executor wasn't started") }; let future = Box::pin(future); @@ -180,6 +183,7 @@ impl WeechatExecutor { F: Future + 'static, F::Output: 'static, { + #[allow(static_mut_refs)] let executor = unsafe { _EXECUTOR.as_ref() }; executor.map(|executor| executor.spawn_local(future)) } @@ -189,6 +193,7 @@ impl WeechatExecutor { F: Future + 'static, F::Output: 'static, { + #[allow(static_mut_refs)] let executor = unsafe { _EXECUTOR.as_ref().expect("Executor wasn't started") }; let sender = Arc::downgrade(&executor.sender); From 8c7a3333f17bf3bfb6f403c93178ce2b742490f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 14:38:44 +0200 Subject: [PATCH 11/12] Fix a docstring mentioning string values for integer config options --- crates/weechat/src/config/integer.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/crates/weechat/src/config/integer.rs b/crates/weechat/src/config/integer.rs index b9677a3..f5ee330 100644 --- a/crates/weechat/src/config/integer.rs +++ b/crates/weechat/src/config/integer.rs @@ -94,7 +94,8 @@ impl IntegerOptionSettings { /// use weechat::config::IntegerOptionSettings; /// /// let settings = IntegerOptionSettings::new("server_buffer") - /// .string_values(vec!["independent", "merged"]) + /// .min(0) + /// .max(100) /// .set_change_callback(|weechat, option| { /// Weechat::print("Option changed"); /// }); From a99b32a4c5465d0e541b314f35b50511184398f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damir=20Jeli=C4=87?= Date: Mon, 14 Oct 2024 14:50:47 +0200 Subject: [PATCH 12/12] fix: Qualify the VARIANTS call in the config macro --- crates/weechat/src/config_macros.rs | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/crates/weechat/src/config_macros.rs b/crates/weechat/src/config_macros.rs index f0d7187..2728647 100644 --- a/crates/weechat/src/config_macros.rs +++ b/crates/weechat/src/config_macros.rs @@ -20,7 +20,10 @@ macro_rules! option_settings { .description($description) .default_value(<$out_type>::default() as i32) .string_values( - <$out_type>::VARIANTS.iter().map(|v| v.to_string()).collect::>(), + <$out_type as weechat::strum::VariantNames>::VARIANTS + .iter() + .map(|v| v.to_string()) + .collect::>(), ); }; }