Struct FunctionBuilder

Source
pub struct FunctionBuilder<'context> { /* private fields */ }
Expand description

Builder for creating native function objects

Implementations§

Source§

impl<'context> FunctionBuilder<'context>

Source

pub fn native(context: &'context mut Context, function: NativeFunction) -> Self

Create a new FunctionBuilder for creating a native function.

Source

pub fn closure<F>(context: &'context mut Context, function: F) -> Self
where F: Fn(&JsValue, &[JsValue], &mut Context) -> JsResult<JsValue> + Copy + 'static,

Create a new FunctionBuilder for creating a closure function.

Source

pub fn closure_with_captures<F, C>( context: &'context mut Context, function: F, captures: C, ) -> Self
where F: Fn(&JsValue, &[JsValue], &mut Context, &mut C) -> JsResult<JsValue> + Copy + 'static, C: NativeObject + Clone,

Create a new closure function with additional captures.

§Note

You can only move variables that implement Debug + Any + Trace + Clone. In other words, only NativeObject + Clone objects are movable.

Source

pub fn name<N>(&mut self, name: N) -> &mut Self
where N: AsRef<str>,

Specify the name property of object function object.

The default is "" (empty string).

Source

pub fn length(&mut self, length: usize) -> &mut Self

Specify the length property of object function object.

How many arguments this function takes.

The default is 0.

Source

pub fn constructable(&mut self, yes: bool) -> &mut Self

Specify the whether the object function object can be called with new keyword.

The default is false.

Source

pub fn build(&mut self) -> JsObject

Build the function object.

Trait Implementations§

Source§

impl<'context> Debug for FunctionBuilder<'context>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'context> !Freeze for FunctionBuilder<'context>

§

impl<'context> !RefUnwindSafe for FunctionBuilder<'context>

§

impl<'context> !Send for FunctionBuilder<'context>

§

impl<'context> !Sync for FunctionBuilder<'context>

§

impl<'context> Unpin for FunctionBuilder<'context>

§

impl<'context> !UnwindSafe for FunctionBuilder<'context>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V