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] 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,