refactor: clean up import paths

This commit is contained in:
Ryan 2025-03-15 15:07:26 -04:00
parent e70b8eca84
commit 41b3375749
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
6 changed files with 14 additions and 14 deletions

View File

@ -1,5 +1,5 @@
use azalea::entity::LookDirection; use azalea::entity::LookDirection;
use mlua::{FromLua, IntoLua, Lua, Result, Value}; use mlua::{Error, FromLua, IntoLua, Lua, Result, Value};
#[derive(Clone)] #[derive(Clone)]
pub struct Direction { pub struct Direction {
@ -37,7 +37,7 @@ impl FromLua for Direction {
} }
}) })
} else { } else {
Err(mlua::Error::FromLuaConversionError { Err(Error::FromLuaConversionError {
from: value.type_name(), from: value.type_name(),
to: "Direction".to_string(), to: "Direction".to_string(),
message: None, message: None,

View File

@ -1,12 +1,12 @@
use super::room::Room; use super::room::Room;
use matrix_sdk::{Client as MatrixClient, ruma::UserId}; use matrix_sdk::{Client as MatrixClient, ruma::UserId};
use mlua::{Error, UserData}; use mlua::{Error, UserData, UserDataFields, UserDataMethods};
use std::sync::Arc; use std::sync::Arc;
pub struct Client(pub Arc<MatrixClient>); pub struct Client(pub Arc<MatrixClient>);
impl UserData for Client { impl UserData for Client {
fn add_fields<F: mlua::UserDataFields<Self>>(f: &mut F) { fn add_fields<F: UserDataFields<Self>>(f: &mut F) {
f.add_field_method_get("rooms", |_, this| { f.add_field_method_get("rooms", |_, this| {
Ok(this.0.rooms().into_iter().map(Room).collect::<Vec<_>>()) Ok(this.0.rooms().into_iter().map(Room).collect::<Vec<_>>())
}); });
@ -15,7 +15,7 @@ impl UserData for Client {
}); });
} }
fn add_methods<M: mlua::UserDataMethods<Self>>(m: &mut M) { fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
m.add_async_method("create_dm", async |_, this, user_id: String| { m.add_async_method("create_dm", async |_, this, user_id: String| {
this.0 this.0
.create_dm(&UserId::parse(user_id).map_err(Error::external)?) .create_dm(&UserId::parse(user_id).map_err(Error::external)?)

View File

@ -1,10 +1,10 @@
use matrix_sdk::room::RoomMember; use matrix_sdk::room::RoomMember;
use mlua::UserData; use mlua::{UserData, UserDataFields};
pub struct Member(pub RoomMember); pub struct Member(pub RoomMember);
impl UserData for Member { impl UserData for Member {
fn add_fields<F: mlua::UserDataFields<Self>>(f: &mut F) { fn add_fields<F: UserDataFields<Self>>(f: &mut F) {
f.add_field_method_get("id", |_, this| Ok(this.0.user_id().to_string())); f.add_field_method_get("id", |_, this| Ok(this.0.user_id().to_string()));
f.add_field_method_get("name", |_, this| Ok(this.0.name().to_owned())); f.add_field_method_get("name", |_, this| Ok(this.0.name().to_owned()));
f.add_field_method_get("power_level", |_, this| Ok(this.0.power_level())); f.add_field_method_get("power_level", |_, this| Ok(this.0.power_level()));

View File

@ -2,12 +2,12 @@ use super::member::Member;
use matrix_sdk::{ use matrix_sdk::{
RoomMemberships, room::Room as MatrixRoom, ruma::events::room::message::RoomMessageEventContent, RoomMemberships, room::Room as MatrixRoom, ruma::events::room::message::RoomMessageEventContent,
}; };
use mlua::{Error, UserData}; use mlua::{Error, UserData, UserDataFields, UserDataMethods};
pub struct Room(pub MatrixRoom); pub struct Room(pub MatrixRoom);
impl UserData for Room { impl UserData for Room {
fn add_fields<F: mlua::UserDataFields<Self>>(f: &mut F) { fn add_fields<F: UserDataFields<Self>>(f: &mut F) {
f.add_field_method_get("id", |_, this| Ok(this.0.room_id().to_string())); f.add_field_method_get("id", |_, this| Ok(this.0.room_id().to_string()));
f.add_field_method_get("name", |_, this| Ok(this.0.name())); f.add_field_method_get("name", |_, this| Ok(this.0.name()));
f.add_field_method_get("topic", |_, this| Ok(this.0.topic())); f.add_field_method_get("topic", |_, this| Ok(this.0.topic()));
@ -16,7 +16,7 @@ impl UserData for Room {
}); });
} }
fn add_methods<M: mlua::UserDataMethods<Self>>(m: &mut M) { fn add_methods<M: UserDataMethods<Self>>(m: &mut M) {
m.add_async_method("send", async |_, this, body: String| { m.add_async_method("send", async |_, this, body: String| {
this.0 this.0
.send(RoomMessageEventContent::text_plain(body)) .send(RoomMessageEventContent::text_plain(body))

View File

@ -1,9 +1,9 @@
use mlua::UserData; use mlua::{UserData, UserDataFields};
pub struct AesKey(pub ncr::AesKey); pub struct AesKey(pub ncr::AesKey);
impl UserData for AesKey { impl UserData for AesKey {
fn add_fields<F: mlua::UserDataFields<Self>>(f: &mut F) { fn add_fields<F: UserDataFields<Self>>(f: &mut F) {
f.add_field_method_get("base64", |_, this| Ok(this.0.encode_base64())); f.add_field_method_get("base64", |_, this| Ok(this.0.encode_base64()));
f.add_field_method_get("bytes", |_, this| Ok(this.0.as_ref().to_vec())); f.add_field_method_get("bytes", |_, this| Ok(this.0.as_ref().to_vec()));
} }

View File

@ -1,5 +1,5 @@
use azalea::{BlockPos, entity::Position}; use azalea::{BlockPos, entity::Position};
use mlua::{FromLua, IntoLua, Lua, Result, Value}; use mlua::{Error, FromLua, IntoLua, Lua, Result, Value};
#[derive(Clone)] #[derive(Clone)]
pub struct Vec3 { pub struct Vec3 {
@ -63,7 +63,7 @@ impl FromLua for Vec3 {
}, },
) )
} else { } else {
Err(mlua::Error::FromLuaConversionError { Err(Error::FromLuaConversionError {
from: value.type_name(), from: value.type_name(),
to: "Vec3".to_string(), to: "Vec3".to_string(),
message: None, message: None,