From 4ac87c72082d7dcac2e86b52cfc6cb8042d481c1 Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 2 Oct 2024 12:21:04 +0100 Subject: [PATCH] Derive `PartialEq` instead of implementing manually --- src/function.rs | 8 +------- src/table.rs | 10 ++-------- src/thread.rs | 9 ++++++++- src/userdata.rs | 10 ++-------- 4 files changed, 13 insertions(+), 24 deletions(-) diff --git a/src/function.rs b/src/function.rs index 3721112..d981f0b 100644 --- a/src/function.rs +++ b/src/function.rs @@ -20,7 +20,7 @@ use { }; /// Handle to an internal Lua function. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct Function(pub(crate) ValueRef); /// Contains information about a function. @@ -509,12 +509,6 @@ impl Function { } } -impl PartialEq for Function { - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 - } -} - pub(crate) struct WrappedFunction(pub(crate) Callback); #[cfg(feature = "async")] diff --git a/src/table.rs b/src/table.rs index 5fb6f20..5fc3ae6 100644 --- a/src/table.rs +++ b/src/table.rs @@ -23,7 +23,7 @@ use crate::value::{FromLua, FromLuaMulti, IntoLua, IntoLuaMulti, Nil, Value}; use futures_util::future::{self, Either, Future}; /// Handle to an internal Lua table. -#[derive(Clone)] +#[derive(Clone, PartialEq)] pub struct Table(pub(crate) ValueRef); impl Table { @@ -806,13 +806,7 @@ impl fmt::Debug for Table { if fmt.alternate() { return self.fmt_pretty(fmt, 0, &mut HashSet::new()); } - fmt.write_fmt(format_args!("Table({:?})", self.0)) - } -} - -impl PartialEq for Table { - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 + fmt.debug_tuple("Table").field(&self.0).finish() } } diff --git a/src/thread.rs b/src/thread.rs index 9553167..8a0f1c3 100644 --- a/src/thread.rs +++ b/src/thread.rs @@ -1,3 +1,4 @@ +use std::fmt; use std::os::raw::{c_int, c_void}; use crate::error::{Error, Result}; @@ -42,7 +43,7 @@ pub enum ThreadStatus { } /// Handle to an internal Lua thread (coroutine). -#[derive(Clone, Debug)] +#[derive(Clone)] pub struct Thread(pub(crate) ValueRef, pub(crate) *mut ffi::lua_State); #[cfg(feature = "send")] @@ -366,6 +367,12 @@ impl Thread { } } +impl fmt::Debug for Thread { + fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result { + fmt.debug_tuple("Thread").field(&self.0).finish() + } +} + impl PartialEq for Thread { fn eq(&self, other: &Self) -> bool { self.0 == other.0 diff --git a/src/userdata.rs b/src/userdata.rs index 71995eb..df299bf 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -128,7 +128,7 @@ pub enum MetaMethod { /// /// Executed when a variable, that marked as to-be-closed, goes out of scope. /// - /// More information about to-be-closed variabled can be found in the Lua 5.4 + /// More information about to-be-closed variables can be found in the Lua 5.4 /// [documentation][lua_doc]. /// /// Requires `feature = "lua54"` @@ -642,7 +642,7 @@ pub trait UserData: Sized { /// [`UserData`]: crate::UserData /// [`is`]: crate::AnyUserData::is /// [`borrow`]: crate::AnyUserData::borrow -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub struct AnyUserData(pub(crate) ValueRef); impl AnyUserData { @@ -1009,12 +1009,6 @@ impl AnyUserData { } } -impl PartialEq for AnyUserData { - fn eq(&self, other: &Self) -> bool { - self.0 == other.0 - } -} - impl AsRef for AnyUserData { #[inline] fn as_ref(&self) -> &Self {