Skip to content

Commit b4892c2

Browse files
committed
Add rustfmt.toml
1 parent 7a75c73 commit b4892c2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+423
-984
lines changed

benches/benchmark.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -183,9 +183,7 @@ fn function_call_concat(c: &mut Criterion) {
183183
let lua = Lua::new();
184184

185185
let concat = lua
186-
.create_function(|_, (a, b): (LuaString, LuaString)| {
187-
Ok(format!("{}{}", a.to_str()?, b.to_str()?))
188-
})
186+
.create_function(|_, (a, b): (LuaString, LuaString)| Ok(format!("{}{}", a.to_str()?, b.to_str()?)))
189187
.unwrap();
190188
let i = AtomicUsize::new(0);
191189

@@ -383,17 +381,10 @@ fn userdata_async_call_method(c: &mut Criterion) {
383381
b.to_async(rt).iter_batched(
384382
|| {
385383
collect_gc_twice(&lua);
386-
(
387-
method.clone(),
388-
ud.clone(),
389-
i.fetch_add(1, Ordering::Relaxed),
390-
)
384+
(method.clone(), ud.clone(), i.fetch_add(1, Ordering::Relaxed))
391385
},
392386
|(method, ud, i)| async move {
393-
assert_eq!(
394-
method.call_async::<_, usize>((ud, i)).await.unwrap(),
395-
123 + i
396-
);
387+
assert_eq!(method.call_async::<_, usize>((ud, i)).await.unwrap(), 123 + i);
397388
},
398389
BatchSize::SmallInput,
399390
);

examples/async_http_server.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ use std::net::SocketAddr;
44
use std::rc::Rc;
55

66
use futures::future::LocalBoxFuture;
7-
use http_body_util::{combinators::BoxBody, BodyExt as _, Empty, Full};
7+
use http_body_util::combinators::BoxBody;
8+
use http_body_util::{BodyExt as _, Empty, Full};
89
use hyper::body::{Bytes, Incoming};
910
use hyper::{Request, Response};
1011
use hyper_util::rt::TokioIo;

examples/async_tcp_server.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ struct LuaTcpStream(TcpStream);
1212

1313
impl UserData for LuaTcpStream {
1414
fn add_methods<'lua, M: UserDataMethods<'lua, Self>>(methods: &mut M) {
15-
methods.add_method("peer_addr", |_, this, ()| {
16-
Ok(this.0.peer_addr()?.to_string())
17-
});
15+
methods.add_method("peer_addr", |_, this, ()| Ok(this.0.peer_addr()?.to_string()));
1816

1917
methods.add_async_method_mut("read", |lua, this, size| async move {
2018
let mut buf = vec![0; size];
@@ -53,9 +51,7 @@ async fn run_server(lua: Lua, handler: RegistryKey) -> io::Result<()> {
5351
let lua = lua.clone();
5452
let handler = handler.clone();
5553
task::spawn_local(async move {
56-
let handler: Function = lua
57-
.registry_value(&handler)
58-
.expect("cannot get Lua handler");
54+
let handler: Function = lua.registry_value(&handler).expect("cannot get Lua handler");
5955

6056
let stream = LuaTcpStream(stream);
6157
if let Err(err) = handler.call_async::<_, ()>(stream).await {

examples/guided_tour.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
use std::f32;
22
use std::iter::FromIterator;
33

4-
use mlua::{
5-
chunk, FromLua, Function, Lua, MetaMethod, Result, UserData, UserDataMethods, Value, Variadic,
6-
};
4+
use mlua::{chunk, FromLua, Function, Lua, MetaMethod, Result, UserData, UserDataMethods, Value, Variadic};
75

86
fn main() -> Result<()> {
97
// You can create a new Lua state with `Lua::new()`. This loads the default Lua std library
@@ -179,13 +177,7 @@ fn main() -> Result<()> {
179177
let vec2_constructor = lua.create_function(|_, (x, y): (f32, f32)| Ok(Vec2(x, y)))?;
180178
globals.set("vec2", vec2_constructor)?;
181179

182-
assert!(
183-
(lua.load("(vec2(1, 2) + vec2(2, 2)):magnitude()")
184-
.eval::<f32>()?
185-
- 5.0)
186-
.abs()
187-
< f32::EPSILON
188-
);
180+
assert!((lua.load("(vec2(1, 2) + vec2(2, 2)):magnitude()").eval::<f32>()? - 5.0).abs() < f32::EPSILON);
189181

190182
// Normally, Rust types passed to `Lua` must be `'static`, because there is no way to be
191183
// sure of their lifetime inside the Lua state. There is, however, a limited way to lift this

examples/serialize.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@ fn main() -> Result<()> {
2828
let globals = lua.globals();
2929

3030
// Create Car struct from a Lua table
31-
let car: Car = lua.from_value(lua.load(r#"
31+
let car: Car = lua.from_value(
32+
lua.load(
33+
r#"
3234
{active = true, model = "Volkswagen Golf", transmission = "Automatic", engine = {v = 1499, kw = 90}}
33-
"#).eval()?)?;
35+
"#,
36+
)
37+
.eval()?,
38+
)?;
3439

3540
// Set it as (serializable) userdata
3641
globals.set("null", lua.null())?;

mlua-sys/src/lib.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ pub const LUA_TRACEBACK_STACK: c_int = 11;
5454
target_arch = "sparc",
5555
target_arch = "wasm32",
5656
target_arch = "hexagon",
57-
all(
58-
target_arch = "riscv32",
59-
not(any(target_os = "espidf", target_os = "zkvm"))
60-
),
57+
all(target_arch = "riscv32", not(any(target_os = "espidf", target_os = "zkvm"))),
6158
all(target_arch = "xtensa", not(target_os = "espidf")),
6259
))]
6360
#[doc(hidden)]

mlua-sys/src/lua51/compat.rs

Lines changed: 5 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22
//!
33
//! Based on github.com/keplerproject/lua-compat-5.3
44
5-
use std::mem;
65
use std::os::raw::{c_char, c_int, c_void};
7-
use std::ptr;
6+
use std::{mem, ptr};
87

98
use super::lauxlib::*;
109
use super::lua::*;
@@ -328,12 +327,7 @@ pub unsafe fn lua_setuservalue(L: *mut lua_State, idx: c_int) {
328327
}
329328

330329
#[inline(always)]
331-
pub unsafe fn lua_dump(
332-
L: *mut lua_State,
333-
writer: lua_Writer,
334-
data: *mut c_void,
335-
_strip: c_int,
336-
) -> c_int {
330+
pub unsafe fn lua_dump(L: *mut lua_State, writer: lua_Writer, data: *mut c_void, _strip: c_int) -> c_int {
337331
lua_dump_(L, writer, data)
338332
}
339333

@@ -365,12 +359,7 @@ pub unsafe fn lua_pushglobaltable(L: *mut lua_State) {
365359
}
366360

367361
#[inline(always)]
368-
pub unsafe fn lua_resume(
369-
L: *mut lua_State,
370-
_from: *mut lua_State,
371-
narg: c_int,
372-
nres: *mut c_int,
373-
) -> c_int {
362+
pub unsafe fn lua_resume(L: *mut lua_State, _from: *mut lua_State, narg: c_int, nres: *mut c_int) -> c_int {
374363
let ret = lua_resume_(L, narg);
375364
if (ret == LUA_OK || ret == LUA_YIELD) && !(nres.is_null()) {
376365
*nres = lua_gettop(L);
@@ -446,12 +435,7 @@ pub unsafe fn luaL_len(L: *mut lua_State, idx: c_int) -> lua_Integer {
446435
res
447436
}
448437

449-
pub unsafe fn luaL_traceback(
450-
L: *mut lua_State,
451-
L1: *mut lua_State,
452-
msg: *const c_char,
453-
mut level: c_int,
454-
) {
438+
pub unsafe fn luaL_traceback(L: *mut lua_State, L1: *mut lua_State, msg: *const c_char, mut level: c_int) {
455439
let mut ar: lua_Debug = mem::zeroed();
456440
let top = lua_gettop(L);
457441
let numlevels = compat53_countlevels(L1);
@@ -543,12 +527,7 @@ pub unsafe fn luaL_getsubtable(L: *mut lua_State, idx: c_int, fname: *const c_ch
543527
0
544528
}
545529

546-
pub unsafe fn luaL_requiref(
547-
L: *mut lua_State,
548-
modname: *const c_char,
549-
openf: lua_CFunction,
550-
glb: c_int,
551-
) {
530+
pub unsafe fn luaL_requiref(L: *mut lua_State, modname: *const c_char, openf: lua_CFunction, glb: c_int) {
552531
luaL_checkstack(L, 3, cstr!("not enough stack slots available"));
553532
luaL_getsubtable(L, LUA_REGISTRYINDEX, cstr!("_LOADED"));
554533
if lua_getfield(L, -1, modname) == LUA_TNIL {

mlua-sys/src/lua51/lauxlib.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,7 @@ extern "C-unwind" {
6363
pub fn luaL_unref(L: *mut lua_State, t: c_int, r#ref: c_int);
6464

6565
pub fn luaL_loadfile(L: *mut lua_State, filename: *const c_char) -> c_int;
66-
pub fn luaL_loadbuffer(
67-
L: *mut lua_State,
68-
buff: *const c_char,
69-
sz: usize,
70-
name: *const c_char,
71-
) -> c_int;
66+
pub fn luaL_loadbuffer(L: *mut lua_State, buff: *const c_char, sz: usize, name: *const c_char) -> c_int;
7267
pub fn luaL_loadstring(L: *mut lua_State, s: *const c_char) -> c_int;
7368

7469
pub fn luaL_newstate() -> *mut lua_State;

mlua-sys/src/lua51/lua.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -379,12 +379,7 @@ extern "C-unwind" {
379379
pub fn lua_getupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
380380
pub fn lua_setupvalue(L: *mut lua_State, funcindex: c_int, n: c_int) -> *const c_char;
381381

382-
pub fn lua_sethook(
383-
L: *mut lua_State,
384-
func: Option<lua_Hook>,
385-
mask: c_int,
386-
count: c_int,
387-
) -> c_int;
382+
pub fn lua_sethook(L: *mut lua_State, func: Option<lua_Hook>, mask: c_int, count: c_int) -> c_int;
388383
pub fn lua_gethook(L: *mut lua_State) -> Option<lua_Hook>;
389384
pub fn lua_gethookmask(L: *mut lua_State) -> c_int;
390385
pub fn lua_gethookcount(L: *mut lua_State) -> c_int;

mlua-sys/src/lua52/compat.rs

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,22 +157,12 @@ pub unsafe fn lua_rawseti(L: *mut lua_State, idx: c_int, n: lua_Integer) {
157157
}
158158

159159
#[inline(always)]
160-
pub unsafe fn lua_dump(
161-
L: *mut lua_State,
162-
writer: lua_Writer,
163-
data: *mut c_void,
164-
_strip: c_int,
165-
) -> c_int {
160+
pub unsafe fn lua_dump(L: *mut lua_State, writer: lua_Writer, data: *mut c_void, _strip: c_int) -> c_int {
166161
lua_dump_(L, writer, data)
167162
}
168163

169164
#[inline(always)]
170-
pub unsafe fn lua_resume(
171-
L: *mut lua_State,
172-
from: *mut lua_State,
173-
narg: c_int,
174-
nres: *mut c_int,
175-
) -> c_int {
165+
pub unsafe fn lua_resume(L: *mut lua_State, from: *mut lua_State, narg: c_int, nres: *mut c_int) -> c_int {
176166
let ret = lua_resume_(L, from, narg);
177167
if (ret == LUA_OK || ret == LUA_YIELD) && !(nres.is_null()) {
178168
*nres = lua_gettop(L);
@@ -240,12 +230,7 @@ pub unsafe fn luaL_tolstring(L: *mut lua_State, mut idx: c_int, len: *mut usize)
240230
lua_tolstring(L, -1, len)
241231
}
242232

243-
pub unsafe fn luaL_requiref(
244-
L: *mut lua_State,
245-
modname: *const c_char,
246-
openf: lua_CFunction,
247-
glb: c_int,
248-
) {
233+
pub unsafe fn luaL_requiref(L: *mut lua_State, modname: *const c_char, openf: lua_CFunction, glb: c_int) {
249234
luaL_checkstack(L, 3, cstr!("not enough stack slots available"));
250235
luaL_getsubtable(L, LUA_REGISTRYINDEX, cstr!("_LOADED"));
251236
if lua_getfield(L, -1, modname) == LUA_TNIL {

0 commit comments

Comments
 (0)