cargo fmt

This commit is contained in:
kyren 2018-09-24 22:13:42 -04:00
parent 70b67052c9
commit 6a5ec6b387
5 changed files with 39 additions and 46 deletions

View File

@ -58,8 +58,8 @@ fn call_add_function(c: &mut Criterion) {
|| { || {
let lua = Lua::new(); let lua = Lua::new();
let f = { let f = {
let f: LuaFunction = let f: LuaFunction = lua
lua.eval( .eval(
r#" r#"
function(a, b, c) function(a, b, c)
return a + b + c return a + b + c
@ -94,8 +94,8 @@ fn call_add_callback(c: &mut Criterion) {
.create_function(|_, (a, b, c): (i64, i64, i64)| Ok(a + b + c)) .create_function(|_, (a, b, c): (i64, i64, i64)| Ok(a + b + c))
.unwrap(); .unwrap();
lua.globals().set("callback", c).unwrap(); lua.globals().set("callback", c).unwrap();
let f: LuaFunction = let f: LuaFunction = lua
lua.eval( .eval(
r#" r#"
function() function()
for i = 1,10 do for i = 1,10 do
@ -126,13 +126,13 @@ fn call_append_callback(c: &mut Criterion) {
|| { || {
let lua = Lua::new(); let lua = Lua::new();
let f = { let f = {
let c: LuaFunction = let c: LuaFunction = lua
lua.create_function(|_, (a, b): (LuaString, LuaString)| { .create_function(|_, (a, b): (LuaString, LuaString)| {
Ok(format!("{}{}", a.to_str()?, b.to_str()?)) Ok(format!("{}{}", a.to_str()?, b.to_str()?))
}).unwrap(); }).unwrap();
lua.globals().set("callback", c).unwrap(); lua.globals().set("callback", c).unwrap();
let f: LuaFunction = let f: LuaFunction = lua
lua.eval( .eval(
r#" r#"
function() function()
for _ = 1,10 do for _ = 1,10 do

View File

@ -16,8 +16,7 @@ fn scope_func() {
.create_function(move |_, ()| { .create_function(move |_, ()| {
r.set(42); r.set(42);
Ok(()) Ok(())
}) }).unwrap();
.unwrap();
lua.globals().set("bad", f.clone()).unwrap(); lua.globals().set("bad", f.clone()).unwrap();
f.call::<_, ()>(()).unwrap(); f.call::<_, ()>(()).unwrap();
assert_eq!(Rc::strong_count(&rc), 2); assert_eq!(Rc::strong_count(&rc), 2);
@ -56,8 +55,7 @@ fn scope_drop() {
scope scope
.create_static_userdata(MyUserdata(rc.clone())) .create_static_userdata(MyUserdata(rc.clone()))
.unwrap(), .unwrap(),
) ).unwrap();
.unwrap();
assert_eq!(Rc::strong_count(&rc), 2); assert_eq!(Rc::strong_count(&rc), 2);
}); });
assert_eq!(Rc::strong_count(&rc), 1); assert_eq!(Rc::strong_count(&rc), 1);
@ -78,8 +76,7 @@ fn scope_capture() {
.create_function_mut(|_, ()| { .create_function_mut(|_, ()| {
i = 42; i = 42;
Ok(()) Ok(())
}) }).unwrap()
.unwrap()
.call::<_, ()>(()) .call::<_, ()>(())
.unwrap(); .unwrap();
}); });
@ -95,8 +92,7 @@ fn outer_lua_access() {
.create_function_mut(|_, ()| { .create_function_mut(|_, ()| {
table.set("a", "b").unwrap(); table.set("a", "b").unwrap();
Ok(()) Ok(())
}) }).unwrap()
.unwrap()
.call::<_, ()>(()) .call::<_, ()>(())
.unwrap(); .unwrap();
}); });
@ -125,8 +121,8 @@ fn scope_userdata_methods() {
let i = Cell::new(42); let i = Cell::new(42);
lua.scope(|scope| { lua.scope(|scope| {
let f: Function = let f: Function = lua
lua.eval( .eval(
r#" r#"
function(u) function(u)
u:inc() u:inc()
@ -165,8 +161,8 @@ fn scope_userdata_functions() {
} }
let lua = Lua::new(); let lua = Lua::new();
let f = let f = lua
lua.exec::<Function>( .exec::<Function>(
r#" r#"
i = 0 i = 0
return function(u) return function(u)

View File

@ -88,8 +88,7 @@ fn test_table() {
.set( .set(
"table4", "table4",
lua.create_sequence_from(vec![1, 2, 3, 4, 5]).unwrap(), lua.create_sequence_from(vec![1, 2, 3, 4, 5]).unwrap(),
) ).unwrap();
.unwrap();
let table4 = globals.get::<_, Table>("table4").unwrap(); let table4 = globals.get::<_, Table>("table4").unwrap();
assert_eq!( assert_eq!(
table4.pairs().collect::<Result<Vec<(i64, i64)>>>().unwrap(), table4.pairs().collect::<Result<Vec<(i64, i64)>>>().unwrap(),
@ -132,8 +131,7 @@ fn test_metatable() {
.set( .set(
"__index", "__index",
lua.create_function(|_, ()| Ok("index_value")).unwrap(), lua.create_function(|_, ()| Ok("index_value")).unwrap(),
) ).unwrap();
.unwrap();
table.set_metatable(Some(metatable)); table.set_metatable(Some(metatable));
assert_eq!(table.get::<_, String>("any_key").unwrap(), "index_value"); assert_eq!(table.get::<_, String>("any_key").unwrap(), "index_value");
match table.raw_get::<_, Value>("any_key").unwrap() { match table.raw_get::<_, Value>("any_key").unwrap() {

View File

@ -47,8 +47,8 @@ fn test_exec() {
).unwrap(); ).unwrap();
assert_eq!(globals.get::<_, String>("res").unwrap(), "foobar"); assert_eq!(globals.get::<_, String>("res").unwrap(), "foobar");
let module: Table = let module: Table = lua
lua.exec( .exec(
r#" r#"
local module = {} local module = {}
@ -324,8 +324,8 @@ fn test_result_conversions() {
let lua = Lua::new(); let lua = Lua::new();
let globals = lua.globals(); let globals = lua.globals();
let err = let err = lua
lua.create_function(|_, ()| { .create_function(|_, ()| {
Ok(Err::<String, _>( Ok(Err::<String, _>(
err_msg("only through failure can we succeed").to_lua_err(), err_msg("only through failure can we succeed").to_lua_err(),
)) ))
@ -520,8 +520,8 @@ fn test_named_registry_value() {
let lua = Lua::new(); let lua = Lua::new();
lua.set_named_registry_value::<i32>("test", 42).unwrap(); lua.set_named_registry_value::<i32>("test", 42).unwrap();
let f = let f = lua
lua.create_function(move |lua, ()| { .create_function(move |lua, ()| {
assert_eq!(lua.named_registry_value::<i32>("test")?, 42); assert_eq!(lua.named_registry_value::<i32>("test")?, 42);
Ok(()) Ok(())
}).unwrap(); }).unwrap();
@ -540,8 +540,8 @@ fn test_registry_value() {
let lua = Lua::new(); let lua = Lua::new();
let mut r = Some(lua.create_registry_value::<i32>(42).unwrap()); let mut r = Some(lua.create_registry_value::<i32>(42).unwrap());
let f = let f = lua
lua.create_function_mut(move |lua, ()| { .create_function_mut(move |lua, ()| {
if let Some(r) = r.take() { if let Some(r) = r.take() {
assert_eq!(lua.registry_value::<i32>(&r)?, 42); assert_eq!(lua.registry_value::<i32>(&r)?, 42);
lua.remove_registry_value(r).unwrap(); lua.remove_registry_value(r).unwrap();
@ -692,11 +692,10 @@ fn large_args() {
} }
Ok(s) Ok(s)
}).unwrap(), }).unwrap(),
) ).unwrap();
.unwrap();
let f: Function = let f: Function = lua
lua.eval( .eval(
r#" r#"
return function(...) return function(...)
return c(...) return c(...)
@ -716,8 +715,8 @@ fn large_args() {
fn large_args_ref() { fn large_args_ref() {
let lua = Lua::new(); let lua = Lua::new();
let f = let f = lua
lua.create_function(|_, args: Variadic<String>| { .create_function(|_, args: Variadic<String>| {
for i in 0..args.len() { for i in 0..args.len() {
assert_eq!(args[i], i.to_string()); assert_eq!(args[i], i.to_string());
} }

View File

@ -7,8 +7,8 @@ use rlua::{Error, Function, Lua, Result, Thread, ThreadStatus};
#[test] #[test]
fn test_thread() { fn test_thread() {
let lua = Lua::new(); let lua = Lua::new();
let thread = let thread = lua
lua.create_thread( .create_thread(
lua.eval::<Function>( lua.eval::<Function>(
r#" r#"
function (s) function (s)
@ -35,8 +35,8 @@ fn test_thread() {
assert_eq!(thread.resume::<_, i64>(4).unwrap(), 10); assert_eq!(thread.resume::<_, i64>(4).unwrap(), 10);
assert_eq!(thread.status(), ThreadStatus::Unresumable); assert_eq!(thread.status(), ThreadStatus::Unresumable);
let accumulate = let accumulate = lua
lua.create_thread( .create_thread(
lua.eval::<Function>( lua.eval::<Function>(
r#" r#"
function (sum) function (sum)
@ -57,8 +57,8 @@ fn test_thread() {
assert!(accumulate.resume::<_, ()>("error").is_err()); assert!(accumulate.resume::<_, ()>("error").is_err());
assert_eq!(accumulate.status(), ThreadStatus::Error); assert_eq!(accumulate.status(), ThreadStatus::Error);
let thread = let thread = lua
lua.eval::<Thread>( .eval::<Thread>(
r#" r#"
coroutine.create(function () coroutine.create(function ()
while true do while true do
@ -71,8 +71,8 @@ fn test_thread() {
assert_eq!(thread.status(), ThreadStatus::Resumable); assert_eq!(thread.status(), ThreadStatus::Resumable);
assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42); assert_eq!(thread.resume::<_, i64>(()).unwrap(), 42);
let thread: Thread = let thread: Thread = lua
lua.eval( .eval(
r#" r#"
coroutine.create(function(arg) coroutine.create(function(arg)
assert(arg == 42) assert(arg == 42)