Skip to content

Commit

Permalink
chore: fix clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Fabrizio Sestito <[email protected]>
  • Loading branch information
fabriziosestito committed Oct 19, 2024
1 parent 26ce19b commit b00995a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 14 deletions.
2 changes: 1 addition & 1 deletion native/rhai_rustler/src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }),
}
}

Expand Down
18 changes: 9 additions & 9 deletions native/rhai_rustler/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,26 +59,26 @@ impl RefUnwindSafe for EvaluationError {}

impl From<Box<EvalAltResult>> for RhaiRustlerError {
fn from(err: Box<EvalAltResult>) -> 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(),
Expand Down Expand Up @@ -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 => {
Expand All @@ -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())
}
}
Expand Down
11 changes: 7 additions & 4 deletions native/rhai_rustler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit b00995a

Please sign in to comment.