small warning / clippy fixes, doc comments

This commit is contained in:
kyren
2017-06-15 16:27:39 -04:00
parent 484479477b
commit 32c83d77b7
4 changed files with 23 additions and 16 deletions
+3 -4
View File
@@ -2,6 +2,8 @@
extern crate hlist_macro;
extern crate rlua;
use std::f32;
use rlua::*;
fn examples() -> LuaResult<()> {
@@ -154,10 +156,7 @@ fn examples() -> LuaResult<()> {
})?;
globals.set("vec2", vec2_constructor)?;
assert_eq!(
lua.eval::<f32>("(vec2(1, 2) + vec2(2, 2)):magnitude()")?,
5.0
);
assert!(lua.eval::<f32>("(vec2(1, 2) + vec2(2, 2)):magnitude()")? - 5.0 < f32::EPSILON);
Ok(())
}
+11 -10
View File
@@ -31,12 +31,12 @@ pub enum LuaValue<'lua> {
}
pub use self::LuaValue::Nil as LuaNil;
/// Trait for types convertible to LuaValue
/// Trait for types convertible to `LuaValue`
pub trait ToLua<'a> {
fn to_lua(self, lua: &'a Lua) -> LuaResult<LuaValue<'a>>;
}
/// Trait for types convertible from LuaValue
/// Trait for types convertible from `LuaValue`
pub trait FromLua<'a>: Sized {
fn from_lua(lua_value: LuaValue<'a>, lua: &'a Lua) -> LuaResult<Self>;
}
@@ -416,8 +416,9 @@ impl<'lua> LuaFunction<'lua> {
}
}
/// A LuaThread is Active before the coroutine function finishes, Dead after it finishes, and in
/// Error state if error has been called inside the coroutine.
/// A `LuaThread` is Active before the coroutine function finishes, Dead after
/// it finishes, and in Error state if error has been called inside the
/// coroutine.
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
pub enum LuaThreadStatus {
Dead,
@@ -430,8 +431,8 @@ pub enum LuaThreadStatus {
pub struct LuaThread<'lua>(LuaRef<'lua>);
impl<'lua> LuaThread<'lua> {
/// If this thread has yielded a value, will return Some, otherwise the thread is finished and
/// this will return None.
/// If this thread has yielded a value, will return Some, otherwise the
/// thread is finished and this will return None.
pub fn resume<A: ToLuaMulti<'lua>, R: FromLuaMulti<'lua>>(
&self,
args: A,
@@ -463,7 +464,7 @@ impl<'lua> LuaThread<'lua> {
for _ in 0..nresults {
results.push_front(lua.pop_value(thread_state)?);
}
R::from_lua_multi(results, lua).map(|r| Some(r))
R::from_lua_multi(results, lua).map(Some)
})
}
}
@@ -614,7 +615,7 @@ pub trait LuaUserDataType: 'static + Sized {
}
/// Handle to an internal instance of custom userdata. All userdata in this API
/// is based around RefCell, to best match the mutable semantics of the lua
/// is based around `RefCell`, to best match the mutable semantics of the lua
/// language.
#[derive(Clone, Debug)]
pub struct LuaUserData<'lua>(LuaRef<'lua>);
@@ -881,7 +882,7 @@ impl Lua {
check_stack(self.state, 3)?;
ffi::lua_newtable(self.state);
for (k, v) in cont.into_iter() {
for (k, v) in cont {
self.push_value(self.state, k.to_lua(self)?)?;
self.push_value(self.state, v.to_lua(self)?)?;
ffi::lua_rawset(self.state, -3);
@@ -947,7 +948,7 @@ impl Lua {
}
/// Returns a handle to the globals table
pub fn globals<'lua>(&'lua self) -> LuaResult<LuaTable<'lua>> {
pub fn globals(&self) -> LuaResult<LuaTable> {
unsafe {
check_stack(self.state, 1)?;
ffi::lua_rawgeti(self.state, ffi::LUA_REGISTRYINDEX, ffi::LUA_RIDX_GLOBALS);
+7
View File
@@ -15,6 +15,9 @@ impl<'lua> FromLuaMulti<'lua> for () {
}
}
/// Result is convertible to `LuaMultiValue` following the common lua idiom of
/// returning the result on success, or in the case of an error, returning nil
/// followed by the error
impl<'lua, T: ToLua<'lua>, E: ToLua<'lua>> ToLuaMulti<'lua> for Result<T, E> {
fn to_lua_multi(self, lua: &'lua Lua) -> LuaResult<LuaMultiValue<'lua>> {
let mut result = LuaMultiValue::new();
@@ -57,6 +60,10 @@ impl<'lua> FromLuaMulti<'lua> for LuaMultiValue<'lua> {
}
}
/// Can be used to pass variadic values to or receive variadic values from lua,
/// where the type of the values is all the same and the number of values is
/// defined at runtime. This can be included in an hlist when unpacking, but
/// must be the final entry, and will consume the rest of the parameters given.
pub struct LuaVariadic<T>(pub Vec<T>);
impl<'lua, T: ToLua<'lua>> ToLuaMulti<'lua> for LuaVariadic<T> {
+2 -2
View File
@@ -631,10 +631,10 @@ fn test_result_conversions() {
let lua = Lua::new();
let globals = lua.globals().unwrap();
let err = lua.create_function(|lua, args| {
let err = lua.create_function(|lua, _| {
lua.pack(Result::Err::<String, String>("only through failure can we succeed".to_string()))
}).unwrap();
let ok = lua.create_function(|lua, args| {
let ok = lua.create_function(|lua, _| {
lua.pack(Result::Ok::<String, String>("!".to_string()))
}).unwrap();