Trait quickjs_rs::Callback

source ·
pub trait Callback<F>: RefUnwindSafe {
    // Required methods
    fn argument_count(&self) -> usize;
    fn call(
        &self,
        args: Vec<JsValue>
    ) -> Result<Result<JsValue, String>, ValueError>;
}
Expand description

The Callback trait is implemented for functions/closures that can be used as callbacks in the JS runtime.

Required Methods§

source

fn argument_count(&self) -> usize

Returns the number of required Javascript arguments.

source

fn call( &self, args: Vec<JsValue> ) -> Result<Result<JsValue, String>, ValueError>

Execute the callback.

Should return:

  • Err(_) if the JS values could not be converted
  • Ok(Err(_)) if an error ocurred while processing. The given error will be raised as a JS exception.
  • Ok(Ok(result)) when execution succeeded.

Implementors§

source§

impl<A1, A2, A3, A4, A5, E, R, F> Callback<PhantomData<(&A1, &A2, &A3, &A4, &A5, &E, &R, &F)>> for Fwhere A1: TryFrom<JsValue, Error = E>, A2: TryFrom<JsValue, Error = E>, A3: TryFrom<JsValue, Error = E>, A4: TryFrom<JsValue, Error = E>, A5: TryFrom<JsValue, Error = E>, ValueError: From<E>, R: IntoCallbackResult, F: Fn(A1, A2, A3, A4, A5) -> R + Sized + RefUnwindSafe,

source§

impl<A1, A2, A3, A4, E, R, F> Callback<PhantomData<(&A1, &A2, &A3, &A4, &E, &R, &F)>> for Fwhere A1: TryFrom<JsValue, Error = E>, A2: TryFrom<JsValue, Error = E>, A3: TryFrom<JsValue, Error = E>, A4: TryFrom<JsValue, Error = E>, ValueError: From<E>, R: IntoCallbackResult, F: Fn(A1, A2, A3, A4) -> R + Sized + RefUnwindSafe,

source§

impl<A1, A2, A3, E, R, F> Callback<PhantomData<(&A1, &A2, &A3, &E, &R, &F)>> for Fwhere A1: TryFrom<JsValue, Error = E>, A2: TryFrom<JsValue, Error = E>, A3: TryFrom<JsValue, Error = E>, ValueError: From<E>, R: IntoCallbackResult, F: Fn(A1, A2, A3) -> R + Sized + RefUnwindSafe,

source§

impl<A1, A2, E, R, F> Callback<PhantomData<(&A1, &A2, &E, &R, &F)>> for Fwhere A1: TryFrom<JsValue, Error = E>, A2: TryFrom<JsValue, Error = E>, ValueError: From<E>, R: IntoCallbackResult, F: Fn(A1, A2) -> R + Sized + RefUnwindSafe,

source§

impl<A1, E, R, F> Callback<PhantomData<(&A1, &E, &R, &F)>> for Fwhere A1: TryFrom<JsValue, Error = E>, ValueError: From<E>, R: IntoCallbackResult, F: Fn(A1) -> R + Sized + RefUnwindSafe,

source§

impl<F> Callback<PhantomData<(&Arguments, &F)>> for Fwhere F: Fn(Arguments) + Sized + RefUnwindSafe,

source§

impl<F, R> Callback<PhantomData<(&Arguments, &F, &R)>> for Fwhere R: IntoCallbackResult, F: Fn(Arguments) -> R + Sized + RefUnwindSafe,

source§

impl<R, F> Callback<PhantomData<(&R, &F)>> for Fwhere R: IntoCallbackResult, F: Fn() -> R + Sized + RefUnwindSafe,