Skip to content

Commit 179c54f

Browse files
committed
Remove generic from Table::equals and Value::equals
1 parent f9ae4bf commit 179c54f

File tree

5 files changed

+13
-36
lines changed

5 files changed

+13
-36
lines changed

src/table.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,12 @@ impl Table {
218218
/// # Ok(())
219219
/// # }
220220
/// ```
221-
pub fn equals<T: AsRef<Self>>(&self, other: T) -> Result<bool> {
222-
let other = other.as_ref();
221+
pub fn equals(&self, other: &Self) -> Result<bool> {
223222
if self == other {
224223
return Ok(true);
225224
}
226225

227-
// Compare using __eq metamethod if exists
226+
// Compare using `__eq` metamethod if exists
228227
// First, check the self for the metamethod.
229228
// If self does not define it, then check the other table.
230229
if let Some(mt) = self.metatable() {
@@ -811,13 +810,6 @@ impl fmt::Debug for Table {
811810
}
812811
}
813812

814-
impl AsRef<Table> for Table {
815-
#[inline]
816-
fn as_ref(&self) -> &Self {
817-
self
818-
}
819-
}
820-
821813
impl<T> PartialEq<[T]> for Table
822814
where
823815
T: IntoLua + Clone,

src/userdata.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ impl AnyUserData {
902902
/// [`UserDataMetatable`]: crate::UserDataMetatable
903903
#[inline]
904904
pub fn metatable(&self) -> Result<UserDataMetatable> {
905-
self.get_raw_metatable().map(UserDataMetatable)
905+
self.raw_metatable().map(UserDataMetatable)
906906
}
907907

908908
#[doc(hidden)]
@@ -911,7 +911,7 @@ impl AnyUserData {
911911
self.metatable()
912912
}
913913

914-
fn get_raw_metatable(&self) -> Result<Table> {
914+
fn raw_metatable(&self) -> Result<Table> {
915915
let lua = self.0.lua.lock();
916916
let state = lua.state();
917917
unsafe {
@@ -958,15 +958,14 @@ impl AnyUserData {
958958
}
959959
}
960960

961-
pub(crate) fn equals<T: AsRef<Self>>(&self, other: T) -> Result<bool> {
962-
let other = other.as_ref();
961+
pub(crate) fn equals(&self, other: &Self) -> Result<bool> {
963962
// Uses lua_rawequal() under the hood
964963
if self == other {
965964
return Ok(true);
966965
}
967966

968-
let mt = self.get_raw_metatable()?;
969-
if mt != other.get_raw_metatable()? {
967+
let mt = self.raw_metatable()?;
968+
if mt != other.raw_metatable()? {
970969
return Ok(false);
971970
}
972971

@@ -1010,13 +1009,6 @@ impl AnyUserData {
10101009
}
10111010
}
10121011

1013-
impl AsRef<AnyUserData> for AnyUserData {
1014-
#[inline]
1015-
fn as_ref(&self) -> &Self {
1016-
self
1017-
}
1018-
}
1019-
10201012
/// Handle to a `UserData` metatable.
10211013
#[derive(Clone, Debug)]
10221014
pub struct UserDataMetatable(pub(crate) Table);

src/value.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ impl Value {
104104
/// Compares two values for equality.
105105
///
106106
/// Equality comparisons do not convert strings to numbers or vice versa.
107-
/// Tables, Functions, Threads, and Userdata are compared by reference:
107+
/// Tables, Functions, Threads, and UserData are compared by reference:
108108
/// two objects are considered equal only if they are the same object.
109109
///
110-
/// If Tables or Userdata have `__eq` metamethod then mlua will try to invoke it.
110+
/// If Tables or UserData have `__eq` metamethod then mlua will try to invoke it.
111111
/// The first value is checked first. If that value does not define a metamethod
112112
/// for `__eq`, then mlua will check the second value.
113113
/// Then mlua calls the metamethod with the two values as arguments, if found.
114-
pub fn equals<T: AsRef<Self>>(&self, other: T) -> Result<bool> {
115-
match (self, other.as_ref()) {
114+
pub fn equals(&self, other: &Self) -> Result<bool> {
115+
match (self, other) {
116116
(Value::Table(a), Value::Table(b)) => a.equals(b),
117117
(Value::UserData(a), Value::UserData(b)) => a.equals(b),
118118
(a, b) => Ok(a == b),
@@ -610,13 +610,6 @@ impl PartialEq for Value {
610610
}
611611
}
612612

613-
impl AsRef<Value> for Value {
614-
#[inline]
615-
fn as_ref(&self) -> &Self {
616-
self
617-
}
618-
}
619-
620613
/// A wrapped [`Value`] with customized serialization behavior.
621614
#[cfg(feature = "serialize")]
622615
#[cfg_attr(docsrs, doc(cfg(feature = "serialize")))]

tests/userdata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ fn test_metamethods() -> Result<()> {
195195

196196
assert!(lua.load("userdata2 == userdata3").eval::<bool>()?);
197197
assert!(userdata2 != userdata3); // because references are differ
198-
assert!(userdata2.equals(userdata3)?);
198+
assert!(userdata2.equals(&userdata3)?);
199199

200200
let userdata1: AnyUserData = globals.get("userdata1")?;
201201
assert!(userdata1.metatable()?.contains(MetaMethod::Add)?);

tests/value.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ fn test_value_eq() -> Result<()> {
5252
assert!(string1 == string2);
5353
assert!(string1.equals(&string2)?);
5454
assert!(num1 == num2);
55-
assert!(num1.equals(num2)?);
55+
assert!(num1.equals(&num2)?);
5656
assert!(num1 != num3);
5757
assert!(func1 == func2);
5858
assert!(func1 != func3);

0 commit comments

Comments
 (0)