diff --git a/oden-js/src/callback.rs b/oden-js/src/callback.rs index 55e7b03a..b8dc3120 100644 --- a/oden-js/src/callback.rs +++ b/oden-js/src/callback.rs @@ -3,9 +3,9 @@ use oden_js_sys as sys; use std::ffi::c_int; use std::panic::catch_unwind; -pub trait Callback: Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> ValueResult {} +pub trait Callback: 'static + Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> ValueResult {} -impl Callback for T where T: Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> ValueResult {} +impl Callback for T where T: 'static + Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> ValueResult {} struct CallbackObject { callback: T, diff --git a/oden-js/src/context.rs b/oden-js/src/context.rs index 5e0f167c..8f2dd651 100644 --- a/oden-js/src/context.rs +++ b/oden-js/src/context.rs @@ -169,14 +169,14 @@ impl ContextRef { } /// Construct a new value that wraps a strongly-typed closure. - pub fn new_fn(&self, func: impl RustFunction) -> ValueResult { - self.new_dynamic_fn(|c, _, a| func.call(c, a)) + pub fn new_fn(&self, func: impl RustFunction + 'static) -> ValueResult { + self.new_dynamic_fn(move |c, _, a| func.call(c, a)) } /// Construct a new value that wraps a dynamically-typed closure. pub fn new_dynamic_fn(&self, func: F) -> ValueResult where - F: Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> ValueResult, + F: 'static + Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> ValueResult, { // Constructing a new function is complicated enough that it needs to // be out of line. @@ -472,7 +472,7 @@ mod tests { go.set_property( &ctx, "foo", - &ctx.new_dynamic_fn(|c, _, _| Ok(return_value.dup(c))) + &ctx.new_dynamic_fn(move |c, _, _| Ok(return_value.dup(c))) .unwrap(), ) .unwrap(); diff --git a/oden-js/src/value.rs b/oden-js/src/value.rs index f8ce5ee3..87450366 100644 --- a/oden-js/src/value.rs +++ b/oden-js/src/value.rs @@ -270,7 +270,7 @@ impl ValueRef { &mut self, ctx: &ContextRef, prop: &str, - func: impl RustFunction, + func: impl RustFunction + 'static, ) -> Result<()> { let vr: Value = ctx.new_fn(func)?; self.set_property(ctx, prop, &vr) @@ -278,7 +278,7 @@ impl ValueRef { pub fn set_dynamic_method(&mut self, ctx: &ContextRef, prop: &str, func: F) -> Result<()> where - F: Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> Result, + F: 'static + Fn(&ContextRef, &ValueRef, &[&ValueRef]) -> Result, { let vr: Value = ctx.new_dynamic_fn(func)?; self.set_property(ctx, prop, &vr)