From 58be62422281b62918959bcd7d74baf05f85bcee Mon Sep 17 00:00:00 2001 From: Alex Orlenko Date: Wed, 20 Mar 2024 19:29:47 +0000 Subject: [PATCH] Remove redundant "match" when checking userdata type via `AnyUserData::is`. Fixes #386 --- src/userdata.rs | 6 +----- tests/userdata.rs | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/userdata.rs b/src/userdata.rs index 1cd6b82..04d6223 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -815,11 +815,7 @@ impl OwnedAnyUserData { impl<'lua> AnyUserData<'lua> { /// Checks whether the type of this userdata is `T`. pub fn is(&self) -> bool { - match self.inspect(|_: &UserDataCell| Ok(())) { - Ok(()) => true, - Err(Error::UserDataTypeMismatch) => false, - Err(_) => unreachable!(), - } + self.inspect(|_: &UserDataCell| Ok(())).is_ok() } /// Borrow this userdata immutably if it is of type `T`. diff --git a/tests/userdata.rs b/tests/userdata.rs index 1f41009..dca5ed2 100644 --- a/tests/userdata.rs +++ b/tests/userdata.rs @@ -370,6 +370,8 @@ fn test_userdata_take() -> Result<()> { r => panic!("improper return for destructed userdata: {:?}", r), } + assert!(!userdata.is::()); + drop(userdata); lua.globals().raw_remove("userdata")?; lua.gc_collect()?;