Struct rquickjs_core::Func [−][src]
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]
Trait Implementations
impl<F> AsRef<F> for Func<F>
[src]
impl<F> Deref for Func<F>
[src]
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]
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,
[src]
N: AsRef<str>,
F: AsFunction<'js, A, R> + ParallelSend + 'static,
Auto Trait Implementations
impl<F> RefUnwindSafe for Func<F> where
F: RefUnwindSafe,
[src]
F: RefUnwindSafe,
impl<F> Send for Func<F> where
F: Send,
[src]
F: Send,
impl<F> Sync for Func<F> where
F: Sync,
[src]
F: Sync,
impl<F> Unpin for Func<F> where
F: Unpin,
[src]
F: Unpin,
impl<F> UnwindSafe for Func<F> where
F: UnwindSafe,
[src]
F: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[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]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,