Skip to content

Commit 58be624

Browse files
committed
Remove redundant "match" when checking userdata type via AnyUserData::is.
Fixes #386
1 parent 3d43103 commit 58be624

File tree

2 files changed

+3
-5
lines changed

2 files changed

+3
-5
lines changed

src/userdata.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -815,11 +815,7 @@ impl OwnedAnyUserData {
815815
impl<'lua> AnyUserData<'lua> {
816816
/// Checks whether the type of this userdata is `T`.
817817
pub fn is<T: 'static>(&self) -> bool {
818-
match self.inspect(|_: &UserDataCell<T>| Ok(())) {
819-
Ok(()) => true,
820-
Err(Error::UserDataTypeMismatch) => false,
821-
Err(_) => unreachable!(),
822-
}
818+
self.inspect(|_: &UserDataCell<T>| Ok(())).is_ok()
823819
}
824820

825821
/// Borrow this userdata immutably if it is of type `T`.

tests/userdata.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,8 @@ fn test_userdata_take() -> Result<()> {
370370
r => panic!("improper return for destructed userdata: {:?}", r),
371371
}
372372

373+
assert!(!userdata.is::<MyUserdata>());
374+
373375
drop(userdata);
374376
lua.globals().raw_remove("userdata")?;
375377
lua.gc_collect()?;

0 commit comments

Comments
 (0)