From db88d3139478ce708144f86227e71467fa9eb5e6 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Fri, 21 Apr 2023 09:07:26 +0200 Subject: [PATCH] Fix strange new compile errors --- src/lib.rs | 1 - src/script_implementations/wasm/extern_ref.rs | 22 ++++++++++++++++++- .../wasm/script_function_cache.rs | 7 ++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 2038c75..5dad32a 100755 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,7 +24,6 @@ #![feature(unboxed_closures)] #![feature(trait_upcasting)] #![feature(lazy_cell)] -#![feature(is_some_and)] //! PkmnLib //! PkmnLib is a full featured implementation of Pokemon. while currently focused on implementing diff --git a/src/script_implementations/wasm/extern_ref.rs b/src/script_implementations/wasm/extern_ref.rs index 6d32a3e..4412449 100755 --- a/src/script_implementations/wasm/extern_ref.rs +++ b/src/script_implementations/wasm/extern_ref.rs @@ -13,7 +13,6 @@ use wasmer::FunctionEnvMut; /// An Extern Ref allows us to pass objects to WASM without actually passing raw memory, or /// requiring us to make copies. Instead, we pass a simple increment index, that we can then use /// to find the relevant data. -#[derive(Copy, Clone)] pub(crate) struct ExternRef { /// The lookup index we can use to find the data. index: usize, @@ -21,6 +20,17 @@ pub(crate) struct ExternRef { _phantom: PhantomData, } +impl Copy for ExternRef {} + +impl Clone for ExternRef { + fn clone(&self) -> Self { + Self { + index: self.index, + _phantom: Default::default(), + } + } +} + impl ExternRef { /// Instantiates a new ExternRef for a bit of data. If we already have made an Extern Ref for /// this data and type, we use that instead. @@ -139,6 +149,16 @@ pub(crate) struct VecExternRef { _phantom: PhantomData, } +impl Clone for VecExternRef { + fn clone(&self) -> Self { + Self { + index: self.index, + size: self.size, + _phantom: Default::default(), + } + } +} + impl VecExternRef { /// Instantiates a new VecExternRef for a given slice. pub fn new(env: &WebAssemblyEnvironmentData, value: &Vec) -> Self { diff --git a/src/script_implementations/wasm/script_function_cache.rs b/src/script_implementations/wasm/script_function_cache.rs index a2ca70f..e7eb05a 100755 --- a/src/script_implementations/wasm/script_function_cache.rs +++ b/src/script_implementations/wasm/script_function_cache.rs @@ -51,11 +51,14 @@ macro_rules! script_function_cache { { let read_lock = self.$name.read(); if let Some(f) = read_lock.as_ref() { - return Some(f.clone()); + return Some(TypedFunction::clone(f)); } } self.[](env); - self.$name.read().as_ref().cloned() + match self.$name.read().as_ref() { + Some(f) => Some(TypedFunction::clone(f)), + None => None, + } } } )*