auto formatting
This commit is contained in:
parent
e41c72d642
commit
0909ca34fc
|
@ -173,9 +173,7 @@ impl<'lua, T: UserData> UserDataMethods<'lua, T> {
|
||||||
R: ToLuaMulti<'lua>,
|
R: ToLuaMulti<'lua>,
|
||||||
F: 'static + FnMut(&'lua Lua, A) -> Result<R>,
|
F: 'static + FnMut(&'lua Lua, A) -> Result<R>,
|
||||||
{
|
{
|
||||||
Box::new(move |lua, args| {
|
Box::new(move |lua, args| function(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua))
|
||||||
function(lua, A::from_lua_multi(args, lua)?)?.to_lua_multi(lua)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn box_method<A, R, M>(mut method: M) -> Callback<'lua>
|
fn box_method<A, R, M>(mut method: M) -> Callback<'lua>
|
||||||
|
@ -332,9 +330,8 @@ impl<'lua> AnyUserData<'lua> {
|
||||||
/// Returns a `UserDataBorrowError` if the userdata is already mutably borrowed. Returns a
|
/// Returns a `UserDataBorrowError` if the userdata is already mutably borrowed. Returns a
|
||||||
/// `UserDataTypeMismatch` if the userdata is not of type `T`.
|
/// `UserDataTypeMismatch` if the userdata is not of type `T`.
|
||||||
pub fn borrow<T: UserData>(&self) -> Result<Ref<T>> {
|
pub fn borrow<T: UserData>(&self) -> Result<Ref<T>> {
|
||||||
self.inspect(|cell| {
|
self.inspect(|cell| Ok(cell.try_borrow().map_err(|_| Error::UserDataBorrowError)?))
|
||||||
Ok(cell.try_borrow().map_err(|_| Error::UserDataBorrowError)?)
|
.ok_or(Error::UserDataTypeMismatch)?
|
||||||
}).ok_or(Error::UserDataTypeMismatch)?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Borrow this userdata mutably if it is of type `T`.
|
/// Borrow this userdata mutably if it is of type `T`.
|
||||||
|
@ -463,14 +460,14 @@ mod tests {
|
||||||
impl UserData for MyUserData {
|
impl UserData for MyUserData {
|
||||||
fn add_methods(methods: &mut UserDataMethods<Self>) {
|
fn add_methods(methods: &mut UserDataMethods<Self>) {
|
||||||
methods.add_method("get", |_, data, ()| Ok(data.0));
|
methods.add_method("get", |_, data, ()| Ok(data.0));
|
||||||
methods
|
methods.add_meta_function(
|
||||||
.add_meta_function(MetaMethod::Add, |_, (lhs, rhs): (MyUserData, MyUserData)| {
|
MetaMethod::Add,
|
||||||
Ok(MyUserData(lhs.0 + rhs.0))
|
|_, (lhs, rhs): (MyUserData, MyUserData)| Ok(MyUserData(lhs.0 + rhs.0)),
|
||||||
});
|
);
|
||||||
methods
|
methods.add_meta_function(
|
||||||
.add_meta_function(MetaMethod::Sub, |_, (lhs, rhs): (MyUserData, MyUserData)| {
|
MetaMethod::Sub,
|
||||||
Ok(MyUserData(lhs.0 - rhs.0))
|
|_, (lhs, rhs): (MyUserData, MyUserData)| Ok(MyUserData(lhs.0 - rhs.0)),
|
||||||
});
|
);
|
||||||
methods.add_meta_method(MetaMethod::Index, |_, data, index: String| {
|
methods.add_meta_method(MetaMethod::Index, |_, data, index: String| {
|
||||||
if index.to_str()? == "inner" {
|
if index.to_str()? == "inner" {
|
||||||
Ok(data.0)
|
Ok(data.0)
|
||||||
|
|
Loading…
Reference in New Issue