Struct rquickjs_core::context::AsyncContext

source ·
pub struct AsyncContext(/* private fields */);
Expand description

An asynchronous single execution context with its own global variables and stack.

Can share objects with other contexts of the same runtime.

Implementations§

source§

impl AsyncContext

source

pub unsafe fn from_raw(ctx: NonNull<JSContext>, rt: AsyncRuntime) -> Self

Create a async context form a raw context pointer.

§Safety

The context must be of the correct runtime. The context must also have valid reference count, one which can be decremented when this object is dropped without going negative.

source

pub async fn base(runtime: &AsyncRuntime) -> Result<Self>

Creates a base context with only the required functions registered. If additional functions are required use AsyncContext::custom, AsyncContext::builder or AsyncContext::full.

source

pub async fn custom<I: Intrinsic>(runtime: &AsyncRuntime) -> Result<Self>

Creates a context with only the required intrinsics registered. If additional functions are required use AsyncContext::custom, AsyncContext::builder or AsyncContext::full.

source

pub async fn full(runtime: &AsyncRuntime) -> Result<Self>

Creates a context with all standard available intrinsics registered. If precise control is required of which functions are available use AsyncContext::custom or AsyncContext::builder.

source

pub fn builder() -> ContextBuilder<()>

Create a context builder for creating a context with a specific set of intrinsics

source

pub async fn enable_big_num_ext(&self, enable: bool)

source

pub fn runtime(&self) -> &AsyncRuntime

Returns the associated runtime

source

pub fn async_with<F, R>(&self, f: F) -> WithFuture<'_, F, R>
where F: for<'js> FnOnce(Ctx<'js>) -> Pin<Box<dyn Future<Output = R> + Send + 'js>> + ParallelSend, R: ParallelSend,

A entry point for manipulating and using JavaScript objects and scripts.

This function is rather limited in what environment it can capture. If you need to borrow the environment in the closure use the async_with! macro.

Unfortunately it is currently impossible to have closures return a generic future which has a higher rank trait bound lifetime. So, to allow closures to work, the closure must return a boxed future.

source

pub async fn with<F, R>(&self, f: F) -> R
where F: for<'js> FnOnce(Ctx<'js>) -> R + ParallelSend, R: ParallelSend,

A entry point for manipulating and using JavaScript objects and scripts.

This closure can’t return a future, if you need to await JavaScript promises prefer the async_with! macro.

Trait Implementations§

source§

impl Clone for AsyncContext

source§

fn clone(&self) -> AsyncContext

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

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>,

§

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<T> ParallelSend for T