diff --git a/src/userdata.rs b/src/userdata.rs index d28a374..ef8cbf4 100644 --- a/src/userdata.rs +++ b/src/userdata.rs @@ -135,7 +135,8 @@ impl fmt::Display for MetaMethod { } impl MetaMethod { - pub(crate) fn name(&self) -> &str { + /// Returns Lua metamethod name, usually prefixed by two underscores. + pub fn name(&self) -> &str { match self { MetaMethod::Add => "__add", MetaMethod::Sub => "__sub", @@ -871,7 +872,7 @@ impl<'lua> UserDataMetatable<'lua> { /// The pairs are wrapped in a [`Result`], since they are lazily converted to `V` type. /// /// [`Result`]: type.Result.html - pub fn pairs, V: FromLua<'lua>>(self) -> UserDataMetatablePairs<'lua, V> { + pub fn pairs>(self) -> UserDataMetatablePairs<'lua, V> { UserDataMetatablePairs(self.0.pairs()) } } diff --git a/tests/userdata.rs b/tests/userdata.rs index 3c45a6f..6256b9e 100644 --- a/tests/userdata.rs +++ b/tests/userdata.rs @@ -416,6 +416,14 @@ fn test_metatable() -> Result<()> { Err(e) => panic!("expected MetaMethodRestricted, got {:?}", e), } + let mut methods = metatable + .pairs() + .into_iter() + .map(|kv: Result<(_, Value)>| Ok(kv?.0)) + .collect::>>()?; + methods.sort_by_cached_key(|k| k.name().to_owned()); + assert_eq!(methods, vec![MetaMethod::Index, "__type_name".into()]); + #[derive(Copy, Clone)] struct MyUserData2(i64);