From b00995a72f4863d36e3dbc0e84c292a3172ba3d7 Mon Sep 17 00:00:00 2001 From: Fabrizio Sestito Date: Sat, 19 Oct 2024 17:59:57 +0200 Subject: [PATCH] chore: fix clippy Signed-off-by: Fabrizio Sestito --- native/rhai_rustler/src/engine.rs | 2 +- native/rhai_rustler/src/error.rs | 18 +++++++++--------- native/rhai_rustler/src/lib.rs | 11 +++++++---- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/native/rhai_rustler/src/engine.rs b/native/rhai_rustler/src/engine.rs index aa43f1c..6b99d41 100644 --- a/native/rhai_rustler/src/engine.rs +++ b/native/rhai_rustler/src/engine.rs @@ -112,7 +112,7 @@ fn engine_register_custom_operator( match engine.register_custom_operator(keyword, precedence) { Ok(_) => Ok(()), - Err(message) => Err(RhaiRustlerError::CustomOperatorError { message }), + Err(message) => Err(RhaiRustlerError::CustomOperator { message }), } } diff --git a/native/rhai_rustler/src/error.rs b/native/rhai_rustler/src/error.rs index 760cb26..e3ff4f7 100644 --- a/native/rhai_rustler/src/error.rs +++ b/native/rhai_rustler/src/error.rs @@ -59,26 +59,26 @@ impl RefUnwindSafe for EvaluationError {} impl From> for RhaiRustlerError { fn from(err: Box) -> Self { - RhaiRustlerError::EvaluationError(EvaluationError(err)) + RhaiRustlerError::Evaluation(EvaluationError(err)) } } #[derive(Error, Debug)] pub enum RhaiRustlerError { #[error("Error in evaluation: {0}.")] - EvaluationError(#[from] EvaluationError), + Evaluation(#[from] EvaluationError), #[error("Error when parsing a script: {0}.")] - ParseError(#[from] ParseError), + Parse(#[from] ParseError), #[error("Error when accessing a scope: {0}.")] - ScopeError(#[from] ScopeError), + Scope(#[from] ScopeError), #[error("Error when defining a custom operator: {message}.")] - CustomOperatorError { message: String }, + CustomOperator { message: String }, } impl Encoder for RhaiRustlerError { fn encode<'a>(&self, env: Env<'a>) -> Term<'a> { match self { - RhaiRustlerError::EvaluationError(EvaluationError(err)) => { + RhaiRustlerError::Evaluation(EvaluationError(err)) => { let error_atom = match err.unwrap_inner() { EvalAltResult::ErrorSystem(_, _) => atoms::system(), EvalAltResult::ErrorParsing(_, _) => atoms::parsing(), @@ -122,10 +122,10 @@ impl Encoder for RhaiRustlerError { make_reason_tuple(env, error_atom, err.to_string()) } - RhaiRustlerError::ParseError(err) => { + RhaiRustlerError::Parse(err) => { make_reason_tuple(env, atoms::parsing(), err.to_string()) } - RhaiRustlerError::ScopeError(err) => { + RhaiRustlerError::Scope(err) => { let error_atom = match err { ScopeError::ErrorScopeIsEmpty => atoms::scope_is_empty(), ScopeError::ErrorCannotUpdateValueOfConstant => { @@ -135,7 +135,7 @@ impl Encoder for RhaiRustlerError { make_reason_tuple(env, error_atom, err.to_string()) } - RhaiRustlerError::CustomOperatorError { message } => { + RhaiRustlerError::CustomOperator { message } => { make_reason_tuple(env, atoms::custom_operator(), message.to_owned()) } } diff --git a/native/rhai_rustler/src/lib.rs b/native/rhai_rustler/src/lib.rs index dd43e6d..8485963 100644 --- a/native/rhai_rustler/src/lib.rs +++ b/native/rhai_rustler/src/lib.rs @@ -21,11 +21,14 @@ fn load(env: Env, _: Term) -> bool { return false; } - rustler::resource!(EngineResource, env); - rustler::resource!(ScopeResource, env); - rustler::resource!(ASTResource, env); + let resources = [ + rustler::resource!(EngineResource, env), + rustler::resource!(ScopeResource, env), + rustler::resource!(ASTResource, env), + ]; - true + // If any resource was not loaded correctly, return false + !resources.into_iter().any(|resource| !resource) } rustler::init!("Elixir.Rhai.Native", load = load);