From 85004c72aec7369a641d81cf8bd2ab81f85b6447 Mon Sep 17 00:00:00 2001 From: Patrick Smith Date: Wed, 3 Apr 2024 14:59:48 +1100 Subject: [PATCH] Minor refactor to return error earlier --- native/wasmex/src/instance.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/native/wasmex/src/instance.rs b/native/wasmex/src/instance.rs index f8ccb0b5..ba12f341 100644 --- a/native/wasmex/src/instance.rs +++ b/native/wasmex/src/instance.rs @@ -93,15 +93,15 @@ pub fn get_global_value( ))) })?); - let global_val = instance + let global = instance .get_global(&mut store_or_caller, &global_name) - .map(|g| g.get(&mut store_or_caller)); + .ok_or_else(|| { + rustler::Error::Term(Box::new(format!( + "exported global `{global_name}` not found" + ))) + })?; - let value = global_val.ok_or_else(|| { - rustler::Error::Term(Box::new(format!( - "exported global `{global_name}` not found" - ))) - })?; + let value = global.get(&mut store_or_caller); match value { Val::I32(i) => Ok(i.encode(env)),