Struct rquickjs_core::Func[][src]

#[repr(transparent)]pub struct Func<F>(pub F);

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");

Implementations

impl<N, F, A, R> Func<(N, F, PhantomData<(A, R)>)>[src]

pub fn new(name: N, func: F) -> Self[src]

Trait Implementations

impl<F> AsRef<F> for Func<F>[src]

impl<F> Deref for Func<F>[src]

type Target = F

The resulting type after dereferencing.

impl<F, A, R> From<F> for Func<(F, PhantomData<(A, R)>)>[src]

impl<'js, F, A, R> IntoJs<'js> for Func<(F, PhantomData<(A, R)>)> where
    F: AsFunction<'js, A, R> + ParallelSend + 'static, 
[src]

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, 
[src]

Auto Trait Implementations

impl<F> RefUnwindSafe for Func<F> where
    F: RefUnwindSafe
[src]

impl<F> Send for Func<F> where
    F: Send
[src]

impl<F> Sync for Func<F> where
    F: Sync
[src]

impl<F> Unpin for Func<F> where
    F: Unpin
[src]

impl<F> UnwindSafe for Func<F> where
    F: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.