Fix some clippy lints, possible edge case API incompatibility around HashMap
This commit is contained in:
parent
4bbeeb2b2d
commit
773bf3e9ba
|
@ -1,5 +1,5 @@
|
|||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::hash::Hash;
|
||||
use std::hash::{BuildHasher, Hash};
|
||||
use std::string::String as StdString;
|
||||
|
||||
use error::*;
|
||||
|
@ -266,13 +266,15 @@ impl<'lua, T: FromLua<'lua>> FromLua<'lua> for Vec<T> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<'lua, K: Eq + Hash + ToLua<'lua>, V: ToLua<'lua>> ToLua<'lua> for HashMap<K, V> {
|
||||
impl<'lua, K: Eq + Hash + ToLua<'lua>, V: ToLua<'lua>, S: BuildHasher> ToLua<'lua>
|
||||
for HashMap<K, V, S> {
|
||||
fn to_lua(self, lua: &'lua Lua) -> Result<Value<'lua>> {
|
||||
Ok(Value::Table(lua.create_table_from(self)?))
|
||||
}
|
||||
}
|
||||
|
||||
impl<'lua, K: Eq + Hash + FromLua<'lua>, V: FromLua<'lua>> FromLua<'lua> for HashMap<K, V> {
|
||||
impl<'lua, K: Eq + Hash + FromLua<'lua>, V: FromLua<'lua>, S: BuildHasher + Default> FromLua<'lua>
|
||||
for HashMap<K, V, S> {
|
||||
fn from_lua(value: Value<'lua>, _: &'lua Lua) -> Result<Self> {
|
||||
if let Value::Table(table) = value {
|
||||
table.pairs().collect()
|
||||
|
|
|
@ -36,7 +36,7 @@ pub const LUA_NOREF: c_int = -2;
|
|||
pub const LUA_REFNIL: c_int = -1;
|
||||
|
||||
pub const LUA_MULTRET: c_int = -1;
|
||||
pub const LUAI_MAXSTACK: c_int = 1000000;
|
||||
pub const LUAI_MAXSTACK: c_int = 1_000_000;
|
||||
pub const LUA_REGISTRYINDEX: c_int = -LUAI_MAXSTACK - 1000;
|
||||
pub const LUA_RIDX_MAINTHREAD: lua_Integer = 1;
|
||||
pub const LUA_RIDX_GLOBALS: lua_Integer = 2;
|
||||
|
|
|
@ -64,8 +64,7 @@ impl<'lua> Value<'lua> {
|
|||
Value::Table(_) => "table",
|
||||
Value::Function(_) => "function",
|
||||
Value::Thread(_) => "thread",
|
||||
Value::UserData(_) => "userdata",
|
||||
Value::Error(_) => "userdata",
|
||||
Value::UserData(_) | Value::Error(_) => "userdata",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -260,8 +260,7 @@ pub unsafe fn pnext(state: *mut ffi::lua_State, index: c_int) -> Result<c_int> {
|
|||
pub unsafe fn handle_error(state: *mut ffi::lua_State, err: c_int) -> Result<()> {
|
||||
if err == ffi::LUA_OK || err == ffi::LUA_YIELD {
|
||||
Ok(())
|
||||
} else {
|
||||
if let Some(err) = pop_wrapped_error(state) {
|
||||
} else if let Some(err) = pop_wrapped_error(state) {
|
||||
Err(err)
|
||||
} else if is_wrapped_panic(state, -1) {
|
||||
let panic = get_userdata::<WrappedPanic>(state, -1);
|
||||
|
@ -272,8 +271,7 @@ pub unsafe fn handle_error(state: *mut ffi::lua_State, err: c_int) -> Result<()>
|
|||
lua_panic!(state, "internal error: panic was resumed twice")
|
||||
}
|
||||
} else {
|
||||
let err_string =
|
||||
if let Some(s) = ffi::lua_tolstring(state, -1, ptr::null_mut()).as_ref() {
|
||||
let err_string = if let Some(s) = ffi::lua_tolstring(state, -1, ptr::null_mut()).as_ref() {
|
||||
CStr::from_ptr(s)
|
||||
.to_str()
|
||||
.unwrap_or_else(|_| "<unprintable error>")
|
||||
|
@ -316,7 +314,6 @@ pub unsafe fn handle_error(state: *mut ffi::lua_State, err: c_int) -> Result<()>
|
|||
_ => lua_panic!(state, "internal error: unrecognized lua error code"),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn push_string(state: *mut ffi::lua_State, s: &str) {
|
||||
|
@ -695,7 +692,7 @@ pub unsafe fn is_wrapped_panic(state: *mut ffi::lua_State, index: c_int) -> bool
|
|||
get_panic_metatable(state);
|
||||
let res = ffi::lua_rawequal(state, -1, -2) != 0;
|
||||
ffi::lua_pop(state, 2);
|
||||
return res;
|
||||
res
|
||||
}
|
||||
|
||||
pub unsafe fn get_error_metatable(state: *mut ffi::lua_State) -> c_int {
|
||||
|
|
Loading…
Reference in New Issue