refactor: small changes

* use `mlua::prelude::*` instead of importing individual things
* `digest()` now returns a `RuntimeError` instead of `ExternalError`
This commit is contained in:
Erica Marigold 2023-10-15 00:21:31 -07:00
parent bfd33e3db5
commit 3c2702b7f0
No known key found for this signature in database
GPG key ID: 2768CC0C23D245D1

View file

@ -1,11 +1,9 @@
use std::sync::Arc;
use crate::lune::builtins::{
FromLua, Lua, LuaError, LuaResult, LuaUserData, LuaUserDataMethods, LuaValue,
};
use anyhow::Result;
use base64::{engine::general_purpose as Base64, Engine as _};
use digest::Digest as _;
use mlua::prelude::*;
use std::sync::Mutex;
// TODO: Proper error handling, remove unwraps
@ -156,8 +154,7 @@ impl LuaUserData for &'static Crypto {
impl LuaUserData for Crypto {
fn add_methods<'lua, M: LuaUserDataMethods<'lua, Self>>(methods: &mut M) {
methods.add_method("digest", |_, this, encoding| {
this.digest(encoding)
.map_err(|_| mlua::Error::external("whoopsie!"))
this.digest(encoding).map_err(mlua::Error::runtime)
});
}
}