pub trait IntoJsFunctionCopied<Args, Ret>: IntoJsFunctionSealed<Args, Ret> + Copy {
// Required method
fn into_js_function_copied(self, context: &mut Context) -> NativeFunction;
}Expand description
The safe equivalent of the UnsafeIntoJsFunction trait.
This can only be used on closures that have the Copy trait.
Since this function is implemented for Fn(...) closures, we can use
it directly when defining a function:
let f = |a: i32, b: i32| a + b;
let f = f.into_js_function_copied(&mut context);
let result = f
.call(
&JsValue::undefined(),
&[JsValue::from(1), JsValue::from(2)],
&mut context,
)
.unwrap();
assert_eq!(result, JsValue::new(3));Required Methods§
Sourcefn into_js_function_copied(self, context: &mut Context) -> NativeFunction
fn into_js_function_copied(self, context: &mut Context) -> NativeFunction
Converts the type into a JS function.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.