Struct rquickjs_core::Func
source · [−]#[repr(transparent)]pub struct Func<F>(pub F);
Expand description
The wrapper for function to convert is into JS
The Rust functions should be wrapped to convert it to JS using IntoJs
trait.
// Anonymous function
ctx.globals().set("sum", Func::from(|a: i32, b: i32| a + b))?;
assert_eq!(ctx.eval::<i32, _>("sum(3, 2)")?, 5);
assert_eq!(ctx.eval::<usize, _>("sum.length")?, 2);
assert!(ctx.eval::<Option<String>, _>("sum.name")?.is_none());
// Named function
ctx.globals().set("prod", Func::new("multiply", |a: i32, b: i32| a * b))?;
assert_eq!(ctx.eval::<i32, _>("prod(3, 2)")?, 6);
assert_eq!(ctx.eval::<usize, _>("prod.length")?, 2);
assert_eq!(ctx.eval::<String, _>("prod.name")?, "multiply");
Tuple Fields
0: F
Implementations
Trait Implementations
sourceimpl<F, A, R> From<F> for Func<(F, PhantomData<(A, R)>)>
impl<F, A, R> From<F> for Func<(F, PhantomData<(A, R)>)>
sourceimpl<'js, F, A, R> IntoJs<'js> for Func<(F, PhantomData<(A, R)>)> where
F: AsFunction<'js, A, R> + ParallelSend + 'static,
impl<'js, F, A, R> IntoJs<'js> for Func<(F, PhantomData<(A, R)>)> where
F: AsFunction<'js, A, R> + ParallelSend + 'static,
sourceimpl<'js, N, F, A, R> IntoJs<'js> for Func<(N, F, PhantomData<(A, R)>)> where
N: AsRef<str>,
F: AsFunction<'js, A, R> + ParallelSend + 'static,
impl<'js, N, F, A, R> IntoJs<'js> for Func<(N, F, PhantomData<(A, R)>)> where
N: AsRef<str>,
F: AsFunction<'js, A, R> + ParallelSend + 'static,
Auto Trait Implementations
impl<F> RefUnwindSafe for Func<F> where
F: RefUnwindSafe,
impl<F> Send for Func<F> where
F: Send,
impl<F> Sync for Func<F> where
F: Sync,
impl<F> Unpin for Func<F> where
F: Unpin,
impl<F> UnwindSafe for Func<F> where
F: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more