pub struct Function<T: JsFunction = fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue> { /* private fields */ }Expand description
Function represents any generic Function in JS, by treating all arguments as JsValue.
It takes a generic parameter of phantom type fn (Arg1, ..., Argn) -> Ret which
is used to type the JS function. For example, Function<fn () -> Number> represents
a function taking no arguments that returns a number.
The 8 generic argument parameters (Arg1 through Arg8) are the argument
types. Arguments not provided enable strict arity checking at compile time.
A void function is represented by fn (Arg) -> Undefined, and not the () unit
type. This is because generics must be based on JS values in the JS generic type system.
The default without any parameters is as a void function - no arguments, Undefined return.
The default generic for Function is fn (JsValue, JsValue, ...) -> JsValue,
representing any function, since all functions safely upcast into this function.
§Arity Enforcement
It is not possible to use call4 or bind4 on a function that does not have
at least 4 arguments — the compiler will reject this because only arguments that
are not None support the trait bound for ErasableGeneric.
§Examples
// A function taking no args, returning Number
let f: Function<Number> = get_some_fn();
// A function taking (String, Number) and returning Boolean
let f: Function<Boolean, String, Number> = get_some_fn();
## Upcasting
To pass a typed `Function` where a different generic Function is expected, `upcast()` may be used
to convert into any generic `Function` at zero cost with type-safety.
MDN documentation (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function)Implementations§
Source§impl Function
impl Function
Sourcepub fn new_with_args(args: &str, body: &str) -> Function
pub fn new_with_args(args: &str, body: &str) -> Function
The Function constructor creates a new Function object. Calling the
constructor directly can create functions dynamically, but suffers from
security and similar (but far less significant) performance issues
similar to eval. However, unlike eval, the Function constructor
allows executing code in the global scope, prompting better programming
habits and allowing for more efficient code minification.
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Sourcepub fn new_with_args_typed(args: &str, body: &str) -> Function<T>
pub fn new_with_args_typed(args: &str, body: &str) -> Function<T>
The Function constructor creates a new Function object. Calling the
constructor directly can create functions dynamically, but suffers from
security and similar (but far less significant) performance issues
similar to eval. However, unlike eval, the Function constructor
allows executing code in the global scope, prompting better programming
habits and allowing for more efficient code minification.
Source§impl Function
impl Function
Sourcepub fn new_no_args(body: &str) -> Function
pub fn new_no_args(body: &str) -> Function
The Function constructor creates a new Function object. Calling the
constructor directly can create functions dynamically, but suffers from
security and similar (but far less significant) performance issues
similar to eval. However, unlike eval, the Function constructor
allows executing code in the global scope, prompting better programming
habits and allowing for more efficient code minification.
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Sourcepub fn new_no_args_typed(body: &str) -> Function<T>
pub fn new_no_args_typed(body: &str) -> Function<T>
The Function constructor creates a new Function object.
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Source§impl<F, Ret> Function<F>where
Ret: JsGeneric,
F: JsFunction<Ret = Ret>,
impl<F, Ret> Function<F>where
Ret: JsGeneric,
F: JsFunction<Ret = Ret>,
Source§impl<Arg1, F, Ret> Function<F>
impl<Arg1, F, Ret> Function<F>
Source§impl<Arg1, Arg2, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2>,
impl<Arg1, Arg2, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction1<Arg1 = Arg1> + JsFunction2<Arg2 = Arg2>,
Source§impl<Arg1, Arg2, Arg3, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3>,
impl<Arg1, Arg2, Arg3, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction3<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3>,
Source§impl<Arg1, Arg2, Arg3, Arg4, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4>,
impl<Arg1, Arg2, Arg3, Arg4, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction4<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4>,
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
Arg5: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5>,
impl<Arg1, Arg2, Arg3, Arg4, Arg5, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
Arg5: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction5<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5>,
Sourcepub fn call5(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
) -> Result<Ret, JsValue>
pub fn call5( &self, context: &JsValue, arg1: &Arg1, arg2: &Arg2, arg3: &Arg3, arg4: &Arg4, arg5: &Arg5, ) -> Result<Ret, JsValue>
The call() method calls a function with a given this value and
arguments provided individually.
Note: Use call() to get exact arity and also checked generic type casting.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
Arg5: JsGeneric,
Arg6: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction6<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5, Arg6 = Arg6>,
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
Arg5: JsGeneric,
Arg6: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction6<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5, Arg6 = Arg6>,
Sourcepub fn call6(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
) -> Result<Ret, JsValue>
pub fn call6( &self, context: &JsValue, arg1: &Arg1, arg2: &Arg2, arg3: &Arg3, arg4: &Arg4, arg5: &Arg5, arg6: &Arg6, ) -> Result<Ret, JsValue>
The call() method calls a function with a given this value and
arguments provided individually.
Note: Use call() to get exact arity and also checked generic type casting.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
Arg5: JsGeneric,
Arg6: JsGeneric,
Arg7: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction7<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5, Arg6 = Arg6, Arg7 = Arg7>,
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
Arg4: JsGeneric,
Arg5: JsGeneric,
Arg6: JsGeneric,
Arg7: JsGeneric,
F: JsFunction<Ret = Ret> + JsFunction7<Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3, Arg4 = Arg4, Arg5 = Arg5, Arg6 = Arg6, Arg7 = Arg7>,
Sourcepub fn call7(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
) -> Result<Ret, JsValue>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Ret: ErasableGenericOwn<JsValue>,
pub fn call7(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
) -> Result<Ret, JsValue>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Ret: ErasableGenericOwn<JsValue>,
The call() method calls a function with a given this value and
arguments provided individually.
Note: Use call() to get exact arity and also checked generic type casting.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
Sourcepub fn call8(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
) -> Result<Ret, JsValue>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Ret: ErasableGenericOwn<JsValue>,
pub fn call8(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
) -> Result<Ret, JsValue>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Ret: ErasableGenericOwn<JsValue>,
The call() method calls a function with a given this value and
arguments provided individually.
Note: Use call() to get exact arity and also checked generic type casting.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
Sourcepub fn call9(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
arg9: &JsValue,
) -> Result<Ret, JsValue>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Ret: ErasableGenericOwn<JsValue>,
👎Deprecated
pub fn call9(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
arg9: &JsValue,
) -> Result<Ret, JsValue>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Ret: ErasableGenericOwn<JsValue>,
The call() method calls a function with a given this value and
arguments provided individually.
Note: Use call() to get exact arity and also checked generic type casting.
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Sourcepub fn bind0(&self, context: &JsValue) -> Function<T>
pub fn bind0(&self, context: &JsValue) -> Function<T>
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, F, Ret> Function<F>
impl<Arg1, F, Ret> Function<F>
Sourcepub fn bind1(
&self,
context: &JsValue,
arg1: &Arg1,
) -> Function<<F as JsFunction1>::Bind1>where
Arg1: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction1>::Bind1>: ErasableGenericOwn<Function<<fn(JsValue) -> JsValue as JsFunction1>::Bind1>>,
pub fn bind1(
&self,
context: &JsValue,
arg1: &Arg1,
) -> Function<<F as JsFunction1>::Bind1>where
Arg1: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction1>::Bind1>: ErasableGenericOwn<Function<<fn(JsValue) -> JsValue as JsFunction1>::Bind1>>,
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2>,
impl<Arg1, Arg2, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
F: JsFunction2<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2>,
Sourcepub fn bind2(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
) -> Function<<F as JsFunction2>::Bind2>
pub fn bind2( &self, context: &JsValue, arg1: &Arg1, arg2: &Arg2, ) -> Function<<F as JsFunction2>::Bind2>
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, Arg3, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3>,
impl<Arg1, Arg2, Arg3, F, Ret> Function<F>where
Ret: JsGeneric,
Arg1: JsGeneric,
Arg2: JsGeneric,
Arg3: JsGeneric,
F: JsFunction3<Ret = Ret, Arg1 = Arg1, Arg2 = Arg2, Arg3 = Arg3>,
Sourcepub fn bind3(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
) -> Function<<F as JsFunction3>::Bind3>
pub fn bind3( &self, context: &JsValue, arg1: &Arg1, arg2: &Arg2, arg3: &Arg3, ) -> Function<<F as JsFunction3>::Bind3>
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, Arg3, Arg4, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, F, Ret> Function<F>
Sourcepub fn bind4(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
) -> Function<<F as JsFunction4>::Bind4>
pub fn bind4( &self, context: &JsValue, arg1: &Arg1, arg2: &Arg2, arg3: &Arg3, arg4: &Arg4, ) -> Function<<F as JsFunction4>::Bind4>
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, Arg5, F, Ret> Function<F>
Sourcepub fn bind5(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
) -> Function<<F as JsFunction5>::Bind5>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction5>::Bind5>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction5>::Bind5>>,
pub fn bind5(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
) -> Function<<F as JsFunction5>::Bind5>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction5>::Bind5>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction5>::Bind5>>,
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, F, Ret> Function<F>
Sourcepub fn bind6(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
) -> Function<<F as JsFunction6>::Bind6>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction6>::Bind6>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction6>::Bind6>>,
pub fn bind6(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
) -> Function<<F as JsFunction6>::Bind6>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction6>::Bind6>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction6>::Bind6>>,
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, F, Ret> Function<F>
Sourcepub fn bind7(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
) -> Function<<F as JsFunction7>::Bind7>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction7>::Bind7>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction7>::Bind7>>,
pub fn bind7(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
) -> Function<<F as JsFunction7>::Bind7>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction7>::Bind7>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction7>::Bind7>>,
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
Sourcepub fn bind8(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
) -> Function<<F as JsFunction8>::Bind8>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction8>::Bind8>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction8>::Bind8>>,
pub fn bind8(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
) -> Function<<F as JsFunction8>::Bind8>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Function<<F as JsFunction8>::Bind8>: ErasableGenericOwn<Function<<fn(JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue, JsValue) -> JsValue as JsFunction8>::Bind8>>,
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
impl<Arg1, Arg2, Arg3, Arg4, Arg5, Arg6, Arg7, Arg8, F, Ret> Function<F>
Sourcepub fn bind9(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
arg9: &JsValue,
) -> Function<fn() -> Ret>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Function<fn() -> Ret>: ErasableGenericOwn<Function<fn() -> JsValue>>,
👎Deprecated
pub fn bind9(
&self,
context: &JsValue,
arg1: &Arg1,
arg2: &Arg2,
arg3: &Arg3,
arg4: &Arg4,
arg5: &Arg5,
arg6: &Arg6,
arg7: &Arg7,
arg8: &Arg8,
arg9: &JsValue,
) -> Function<fn() -> Ret>where
Arg1: ErasableGenericBorrow<JsValue>,
Arg2: ErasableGenericBorrow<JsValue>,
Arg3: ErasableGenericBorrow<JsValue>,
Arg4: ErasableGenericBorrow<JsValue>,
Arg5: ErasableGenericBorrow<JsValue>,
Arg6: ErasableGenericBorrow<JsValue>,
Arg7: ErasableGenericBorrow<JsValue>,
Arg8: ErasableGenericBorrow<JsValue>,
Function<fn() -> Ret>: ErasableGenericOwn<Function<fn() -> JsValue>>,
The bind() method creates a new function that, when called, has its this keyword set to the provided value,
with a given sequence of arguments preceding any provided when the new function is called.
Note: See Function::bindn for arbitrary binding with function arity checking.
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Source§impl<T> Function<T>where
T: JsFunction,
impl<T> Function<T>where
T: JsFunction,
Source§impl<T: JsFunction> Function<T>
impl<T: JsFunction> Function<T>
Source§impl<T: JsFunction> Function<T>
impl<T: JsFunction> Function<T>
Sourcepub fn call<Args: JsArgs<T>>(
&self,
context: &JsValue,
args: Args,
) -> Result<T::Ret, JsValue>
pub fn call<Args: JsArgs<T>>( &self, context: &JsValue, args: Args, ) -> Result<T::Ret, JsValue>
The call() method calls a function with a given this value and
arguments provided as a tuple.
This method accepts a tuple of references matching the function’s argument types.
§Example
// 0-arg function
let f: Function<fn() -> Number> = get_fn();
let result = f.call(&JsValue::NULL, ())?;
// 1-arg function (note trailing comma for 1-tuple)
let f: Function<fn(JsString) -> Number> = get_fn();
let result = f.call(&JsValue::NULL, (&name,))?;
// 2-arg function
let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
let result = f.call(&JsValue::NULL, (&name, &flag))?;Sourcepub fn bindn<Args: JsArgs<T>>(
&self,
context: &JsValue,
args: Args,
) -> Args::BindOutput
pub fn bindn<Args: JsArgs<T>>( &self, context: &JsValue, args: Args, ) -> Args::BindOutput
The bind() method creates a new function that, when called, has its
this keyword set to the provided value, with a given sequence of
arguments preceding any provided when the new function is called.
This method accepts a tuple of references to bind.
§Example
let f: Function<fn(JsString, Boolean) -> Number> = get_fn();
// Bind no args - same signature
let bound: Function<fn(JsString, Boolean) -> Number> = f.bind(&ctx, ());
// Bind one arg (use 1-tuple of references)
let bound: Function<fn(Boolean) -> Number> = f.bind(&ctx, (&my_string,));
// Bind two args - becomes 0-arg function
let bound: Function<fn() -> Number> = f.bind(&ctx, (&my_string, &my_bool));Source§impl<F: JsFunction> Function<F>
impl<F: JsFunction> Function<F>
Sourcepub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Selfwhere
F: FunctionIntoClosure,
C: WasmClosure + ?Sized,
<F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
pub fn closure_ref<'a, C>(closure: &'a ScopedClosure<'_, C>) -> &'a Selfwhere
F: FunctionIntoClosure,
C: WasmClosure + ?Sized,
<F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
Convert a borrowed ScopedClosure into a typed JavaScript Function reference.
The conversion is a direct type-safe conversion and upcast of a
closure into its corresponding typed JavaScript Function,
based on covariance and contravariance Upcast trait hierarchy.
For transferring ownership to JS, use Function::from_closure.
Sourcepub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Selfwhere
F: FunctionIntoClosure,
C: WasmClosure + ?Sized,
<F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
pub fn from_closure<C>(closure: ScopedClosure<'static, C>) -> Selfwhere
F: FunctionIntoClosure,
C: WasmClosure + ?Sized,
<F as FunctionIntoClosure>::ClosureTypeMut: UpcastFrom<<C as WasmClosure>::AsMut>,
Convert a Rust closure into a typed JavaScript Function.
This function releases ownership of the closure to JS, and provides an owned function handle for the same closure.
The conversion is a direct type-safe conversion and upcast of a
closure into its corresponding typed JavaScript Function,
based on covariance and contravariance Upcast trait hierarchy.
This method is only supported for static closures which do not have borrowed lifetime data, and thus can be released into JS.
For borrowed closures, which cannot cede ownership to JS,
instead use Function::closure_ref.
Methods from Deref<Target = Object>§
Sourcepub fn constructor(&self) -> Function
pub fn constructor(&self) -> Function
The constructor property returns a reference to the Object constructor
function that created the instance object.
Sourcepub fn has_own_property(&self, property: &JsValue) -> bool
👎Deprecated: Use Object::hasOwn instead.
pub fn has_own_property(&self, property: &JsValue) -> bool
Object::hasOwn instead.The hasOwnProperty() method returns a boolean indicating whether the
object has the specified property as its own property (as opposed to
inheriting it).
Sourcepub fn is_prototype_of(&self, value: &JsValue) -> bool
pub fn is_prototype_of(&self, value: &JsValue) -> bool
The isPrototypeOf() method checks if an object exists in another
object’s prototype chain.
Sourcepub fn property_is_enumerable(&self, property: &JsValue) -> bool
pub fn property_is_enumerable(&self, property: &JsValue) -> bool
The propertyIsEnumerable() method returns a Boolean indicating
whether the specified property is enumerable.
Sourcepub fn to_locale_string(&self) -> JsString
pub fn to_locale_string(&self) -> JsString
The toLocaleString() method returns a string representing the object.
This method is meant to be overridden by derived objects for
locale-specific purposes.
Sourcepub fn to_string(&self) -> JsString
pub fn to_string(&self) -> JsString
The toString() method returns a string representing the object.
Sourcepub fn to_js_string(&self) -> JsString
pub fn to_js_string(&self) -> JsString
The toString() method returns a string representing the object.
Methods from Deref<Target = JsValue>§
pub const NULL: JsValue
pub const UNDEFINED: JsValue
pub const TRUE: JsValue
pub const FALSE: JsValue
Sourcepub fn as_f64(&self) -> Option<f64>
pub fn as_f64(&self) -> Option<f64>
Returns the f64 value of this JS value if it’s an instance of a
number.
If this JS value is not an instance of a number then this returns
None.
Sourcepub fn as_string(&self) -> Option<String>
pub fn as_string(&self) -> Option<String>
If this JS value is a string value, this function copies the JS string
value into Wasm linear memory, encoded as UTF-8, and returns it as a
Rust String.
To avoid the copying and re-encoding, consider the
JsString::try_from() function from js-sys
instead.
If this JS value is not an instance of a string or if it’s not valid
utf-8 then this returns None.
§UTF-16 vs UTF-8
JavaScript strings in general are encoded as UTF-16, but Rust strings
are encoded as UTF-8. This can cause the Rust string to look a bit
different than the JS string sometimes. For more details see the
documentation about the str type which contains a few
caveats about the encodings.
Sourcepub fn as_bool(&self) -> Option<bool>
pub fn as_bool(&self) -> Option<bool>
Returns the bool value of this JS value if it’s an instance of a
boolean.
If this JS value is not an instance of a boolean then this returns
None.
Sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Tests whether this JS value is undefined
Sourcepub fn is_null_or_undefined(&self) -> bool
pub fn is_null_or_undefined(&self) -> bool
Tests whether this JS value is null or undefined
Sourcepub fn is_function(&self) -> bool
pub fn is_function(&self) -> bool
Tests whether the type of this JS value is function.
Sourcepub fn js_in(&self, obj: &JsValue) -> bool
pub fn js_in(&self, obj: &JsValue) -> bool
Applies the binary in JS operator on the two JsValues.
Sourcepub fn loose_eq(&self, other: &JsValue) -> bool
pub fn loose_eq(&self, other: &JsValue) -> bool
Compare two JsValues for equality, using the == operator in JS.
Sourcepub fn unsigned_shr(&self, rhs: &JsValue) -> u32
pub fn unsigned_shr(&self, rhs: &JsValue) -> u32
Applies the binary >>> JS operator on the two JsValues.
Sourcepub fn checked_div(&self, rhs: &JsValue) -> JsValue
pub fn checked_div(&self, rhs: &JsValue) -> JsValue
Applies the binary / JS operator on two JsValues, catching and returning any RangeError thrown.
Sourcepub fn pow(&self, rhs: &JsValue) -> JsValue
pub fn pow(&self, rhs: &JsValue) -> JsValue
Applies the binary ** JS operator on the two JsValues.
Sourcepub fn lt(&self, other: &JsValue) -> bool
pub fn lt(&self, other: &JsValue) -> bool
Applies the binary < JS operator on the two JsValues.
Sourcepub fn le(&self, other: &JsValue) -> bool
pub fn le(&self, other: &JsValue) -> bool
Applies the binary <= JS operator on the two JsValues.
Sourcepub fn ge(&self, other: &JsValue) -> bool
pub fn ge(&self, other: &JsValue) -> bool
Applies the binary >= JS operator on the two JsValues.
Sourcepub fn gt(&self, other: &JsValue) -> bool
pub fn gt(&self, other: &JsValue) -> bool
Applies the binary > JS operator on the two JsValues.
Sourcepub fn unchecked_into_f64(&self) -> f64
pub fn unchecked_into_f64(&self) -> f64
Applies the unary + JS operator on a JsValue. Can throw.
Trait Implementations§
Source§impl<T: JsFunction> Deref for Function<T>
impl<T: JsFunction> Deref for Function<T>
Source§impl<T: JsFunction> ErasableGeneric for Function<T>
impl<T: JsFunction> ErasableGeneric for Function<T>
Source§impl<T: JsFunction> FromWasmAbi for Function<T>
impl<T: JsFunction> FromWasmAbi for Function<T>
Source§impl<'a, T: JsFunction> IntoWasmAbi for &'a Function<T>
impl<'a, T: JsFunction> IntoWasmAbi for &'a Function<T>
Source§impl<T: JsFunction> IntoWasmAbi for Function<T>
impl<T: JsFunction> IntoWasmAbi for Function<T>
Source§impl<T: JsFunction> JsCast for Function<T>
impl<T: JsFunction> JsCast for Function<T>
Source§fn instanceof(val: &JsValue) -> bool
fn instanceof(val: &JsValue) -> bool
instanceof check to see whether the JsValue
provided is an instance of this type. Read moreSource§fn is_type_of(val: &JsValue) -> bool
fn is_type_of(val: &JsValue) -> bool
JsValue provided
is a value of this type. Read moreSource§fn unchecked_from_js(val: JsValue) -> Self
fn unchecked_from_js(val: JsValue) -> Self
Source§fn unchecked_from_js_ref(val: &JsValue) -> &Self
fn unchecked_from_js_ref(val: &JsValue) -> &Self
Source§fn has_type<T>(&self) -> boolwhere
T: JsCast,
fn has_type<T>(&self) -> boolwhere
T: JsCast,
T. Read moreSource§fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
fn dyn_into<T>(self) -> Result<T, Self>where
T: JsCast,
T. Read moreSource§fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
fn dyn_ref<T>(&self) -> Option<&T>where
T: JsCast,
T. Read moreSource§fn unchecked_into<T>(self) -> Twhere
T: JsCast,
fn unchecked_into<T>(self) -> Twhere
T: JsCast,
Source§impl<T: JsFunction> LongRefFromWasmAbi for Function<T>
impl<T: JsFunction> LongRefFromWasmAbi for Function<T>
Source§impl<T: JsFunction> OptionFromWasmAbi for Function<T>
impl<T: JsFunction> OptionFromWasmAbi for Function<T>
Source§impl<'a, T: JsFunction> OptionIntoWasmAbi for &'a Function<T>
impl<'a, T: JsFunction> OptionIntoWasmAbi for &'a Function<T>
Source§impl<T: JsFunction> OptionIntoWasmAbi for Function<T>
impl<T: JsFunction> OptionIntoWasmAbi for Function<T>
Source§impl<T: JsFunction> Promising for Function<T>
impl<T: JsFunction> Promising for Function<T>
Source§type Resolution = Function<T>
type Resolution = Function<T>
Source§impl<T: JsFunction> RefFromWasmAbi for Function<T>
impl<T: JsFunction> RefFromWasmAbi for Function<T>
Source§type Abi = <JsValue as RefFromWasmAbi>::Abi
type Abi = <JsValue as RefFromWasmAbi>::Abi
Self are recovered from.Source§type Anchor = ManuallyDrop<Function<T>>
type Anchor = ManuallyDrop<Function<T>>
Self for the duration of the
invocation of the function that has an &Self parameter. This is
required to ensure that the lifetimes don’t persist beyond one function
call, and so that they remain anonymous.impl<T: Eq + JsFunction> Eq for Function<T>
impl<T: JsFunction> StructuralPartialEq for Function<T>
impl<T: JsFunction, U> UpcastFrom<Function<T>> for Function<U>where
U: UpcastFrom<T> + JsFunction,
impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<JsValue>
impl<T: JsFunction> UpcastFrom<Function<T>> for JsOption<Object>
impl<T: JsFunction> UpcastFrom<Function<T>> for JsValue
impl<T: JsFunction> UpcastFrom<Function<T>> for Object
Auto Trait Implementations§
impl<T> Freeze for Function<T>
impl<T> RefUnwindSafe for Function<T>where
T: RefUnwindSafe,
impl<T> Send for Function<T>where
T: Send,
impl<T> Sync for Function<T>where
T: Sync,
impl<T> Unpin for Function<T>where
T: Unpin,
impl<T> UnsafeUnpin for Function<T>
impl<T> UnwindSafe for Function<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
impl<T> ReturnWasmAbi for Twhere
T: IntoWasmAbi,
Source§type Abi = <T as IntoWasmAbi>::Abi
type Abi = <T as IntoWasmAbi>::Abi
IntoWasmAbi::AbiSource§fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
fn return_abi(self) -> <T as ReturnWasmAbi>::Abi
IntoWasmAbi::into_abi, except that it may throw and never
return in the case of Err.