Skip to content

Commit

Permalink
chore: Fix all the clippy warnings we have
Browse files Browse the repository at this point in the history
  • Loading branch information
poljar committed Oct 14, 2024
1 parent 015550d commit f2cb806
Show file tree
Hide file tree
Showing 21 changed files with 110 additions and 117 deletions.
4 changes: 3 additions & 1 deletion crates/weechat-macro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
23 changes: 10 additions & 13 deletions crates/weechat/src/buffer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand All @@ -95,7 +95,7 @@ impl PartialEq for Buffer<'_> {

impl PartialOrd for Buffer<'_> {
fn partial_cmp(&self, other: &Buffer) -> Option<Ordering> {
self.number().partial_cmp(&other.number())
Some(self.number().cmp(&other.number()))
}
}

Expand Down Expand Up @@ -220,7 +220,6 @@ impl<T: FnMut(&Weechat, &Buffer) -> Result<(), ()> + 'static> BufferCloseCallbac
}

#[cfg(feature = "async")]
#[cfg_attr(feature = "docs", doc(cfg(r#async)))]
#[async_trait(?Send)]
/// Trait for the buffer input callback.
///
Expand Down Expand Up @@ -253,7 +252,6 @@ impl<T: FnMut(BufferHandle, String) -> 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,
Expand All @@ -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.
///
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<BufferHandle, ()> {
unsafe extern "C" fn c_input_cb(
pointer: *const c_void,
Expand Down Expand Up @@ -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(());
}

Expand Down Expand Up @@ -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(());
}

Expand Down Expand Up @@ -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,
}
}
Expand Down Expand Up @@ -830,7 +827,7 @@ impl Buffer<'_> {
/// Returns a `Nick` if one is found, None otherwise.
pub fn search_nick(&self, nick: &str) -> Option<Nick> {
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
Expand Down Expand Up @@ -871,7 +868,7 @@ impl Buffer<'_> {
/// error otherwise.
pub fn add_nick(&self, nick_settings: NickSettings) -> Result<Nick, ()> {
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(());
Expand Down
2 changes: 1 addition & 1 deletion crates/weechat/src/buffer/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
6 changes: 4 additions & 2 deletions crates/weechat/src/config/boolean.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{
Weechat,
};

type BooleanChangeCallback = Box<dyn FnMut(&Weechat, &BooleanOption)>;

/// Settings for a new boolean option.
#[derive(Default)]
pub struct BooleanOptionSettings {
Expand All @@ -19,7 +21,7 @@ pub struct BooleanOptionSettings {

pub(crate) default_value: bool,

pub(crate) change_cb: Option<Box<dyn FnMut(&Weechat, &BooleanOption)>>,
pub(crate) change_cb: Option<BooleanChangeCallback>,
}

impl BooleanOptionSettings {
Expand Down Expand Up @@ -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<bool> for BooleanOption<'a> {
fn eq(&self, other: &bool) -> bool {
Expand Down
6 changes: 4 additions & 2 deletions crates/weechat/src/config/color.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{
Weechat,
};

type ColorChangeCallback = Box<dyn FnMut(&Weechat, &ColorOption)>;

/// Settings for a new color option.
#[derive(Default)]
pub struct ColorOptionSettings {
Expand All @@ -19,7 +21,7 @@ pub struct ColorOptionSettings {

pub(crate) default_value: String,

pub(crate) change_cb: Option<Box<dyn FnMut(&Weechat, &ColorOption)>>,
pub(crate) change_cb: Option<ColorChangeCallback>,
}

impl ColorOptionSettings {
Expand Down Expand Up @@ -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> {}
21 changes: 8 additions & 13 deletions crates/weechat/src/config/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<ConfigOption> {
let weechat = Weechat::from_ptr(self.ptr);
let config_get = weechat.get().config_get.unwrap();
Expand Down Expand Up @@ -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)
}
}
}
Expand All @@ -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)
};
}
Expand Down Expand Up @@ -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
///
Expand Down Expand Up @@ -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 });
Expand All @@ -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(());
};

Expand Down Expand Up @@ -367,7 +362,7 @@ impl Config {
/// # Arguments
///
/// * `section_settings` - Settings that decide how the section will be
/// created.
/// created.
///
/// # Panics
///
Expand Down Expand Up @@ -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(());
};

Expand Down
5 changes: 3 additions & 2 deletions crates/weechat/src/config/config_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,11 @@ pub trait BaseConfigOption: HiddenConfigOptionT {
pub trait ConfigOptions: BaseConfigOption + FromPtrs {}

pub(crate) type CheckCB<T> = dyn FnMut(&Weechat, &T, Cow<str>) -> bool;
pub(crate) type OptionCallback<T> = Box<dyn FnMut(&Weechat, &T)>;

pub(crate) struct OptionPointers<T> {
pub(crate) weechat_ptr: *mut t_weechat_plugin,
pub(crate) check_cb: Option<Box<CheckCB<T>>>,
pub(crate) change_cb: Option<Box<dyn FnMut(&Weechat, &T)>>,
pub(crate) delete_cb: Option<Box<dyn FnMut(&Weechat, &T)>>,
pub(crate) change_cb: Option<OptionCallback<T>>,
pub(crate) delete_cb: Option<OptionCallback<T>>,
}
6 changes: 4 additions & 2 deletions crates/weechat/src/config/enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{
Weechat,
};

type EnumChangeCallback = Box<dyn FnMut(&Weechat, &EnumOption)>;

/// Settings for a new string option.
#[derive(Default)]
pub struct EnumOptionSettings {
Expand All @@ -25,7 +27,7 @@ pub struct EnumOptionSettings {

pub(crate) string_values: String,

pub(crate) change_cb: Option<Box<dyn FnMut(&Weechat, &EnumOption)>>,
pub(crate) change_cb: Option<EnumChangeCallback>,
}

impl EnumOptionSettings {
Expand Down Expand Up @@ -165,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> {}
6 changes: 4 additions & 2 deletions crates/weechat/src/config/integer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ use crate::{
Weechat,
};

type IntegerOptionCallback = Box<dyn FnMut(&Weechat, &IntegerOption)>;

/// Settings for a new integer option.
#[derive(Default)]
pub struct IntegerOptionSettings {
Expand All @@ -23,7 +25,7 @@ pub struct IntegerOptionSettings {

pub(crate) max: i32,

pub(crate) change_cb: Option<Box<dyn FnMut(&Weechat, &IntegerOption)>>,
pub(crate) change_cb: Option<IntegerOptionCallback>,
}

impl IntegerOptionSettings {
Expand Down Expand Up @@ -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> {}
Loading

0 comments on commit f2cb806

Please sign in to comment.