summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Orlenko <zxteam@protonmail.com>2024-03-20 19:29:47 +0000
committerAlex Orlenko <zxteam@protonmail.com>2024-03-20 19:29:47 +0000
commit58be62422281b62918959bcd7d74baf05f85bcee (patch)
treeb4d6bf5c270584a8bf7a5b6f075918c00f9e111f
parent3d431034310711818d96cdd8c64ad2c437710f84 (diff)
downloadmlua-58be62422281b62918959bcd7d74baf05f85bcee.zip
Remove redundant "match" when checking userdata type via `AnyUserData::is`.
Fixes #386
-rw-r--r--src/userdata.rs6
-rw-r--r--tests/userdata.rs2
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<T: 'static>(&self) -> bool {
- match self.inspect(|_: &UserDataCell<T>| Ok(())) {
- Ok(()) => true,
- Err(Error::UserDataTypeMismatch) => false,
- Err(_) => unreachable!(),
- }
+ self.inspect(|_: &UserDataCell<T>| 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::<MyUserdata>());
+
drop(userdata);
lua.globals().raw_remove("userdata")?;
lua.gc_collect()?;