Struct rquickjs::Runtime

source ·
pub struct Runtime { /* private fields */ }
Expand description

QuickJS runtime, entry point of the library.

Implementations§

source§

impl Runtime

source

pub fn new() -> Result<Runtime, Error>

Create a new runtime.

Will generally only fail if not enough memory was available.

§Features

If the "rust-alloc" feature is enabled the Rust’s global allocator will be used in favor of libc’s one.

source

pub fn new_with_alloc<A>(allocator: A) -> Result<Runtime, Error>
where A: Allocator + 'static,

Available on crate feature allocator only.

Create a new runtime using specified allocator

Will generally only fail if not enough memory was available.

source

pub fn weak(&self) -> WeakRuntime

Get weak ref to runtime

source

pub fn set_interrupt_handler( &self, handler: Option<Box<dyn FnMut() -> bool + Send>> )

Set a closure which is regularly called by the engine when it is executing code. If the provided closure returns true the interpreter will raise and uncatchable exception and return control flow to the caller.

source

pub fn set_loader<R, L>(&self, resolver: R, loader: L)
where R: Resolver + 'static, L: Loader + 'static,

Available on crate feature loader only.

Set the module loader

source

pub fn set_info<S>(&self, info: S) -> Result<(), Error>
where S: Into<Vec<u8>>,

Set the info of the runtime

source

pub fn set_memory_limit(&self, limit: usize)

Set a limit on the max amount of memory the runtime will use.

Setting the limit to 0 is equivalent to unlimited memory.

Note that is a Noop when a custom allocator is being used, as is the case for the “rust-alloc” or “allocator” features.

source

pub fn set_max_stack_size(&self, limit: usize)

Set a limit on the max size of stack the runtime will use.

The default values is 256x1024 bytes.

source

pub fn set_gc_threshold(&self, threshold: usize)

Set a memory threshold for garbage collection.

source

pub fn run_gc(&self)

Manually run the garbage collection.

Most of QuickJS values are reference counted and will automatically free themselves when they have no more references. The garbage collector is only for collecting cyclic references.

source

pub fn memory_usage(&self) -> JSMemoryUsage

Get memory usage stats

source

pub fn is_job_pending(&self) -> bool

Test for pending jobs

Returns true when at least one job is pending.

source

pub fn execute_pending_job(&self) -> Result<bool, JobException>

Execute first pending job

Returns true when job was executed or false when queue is empty or error when exception thrown under execution.

Trait Implementations§

source§

impl Clone for Runtime

source§

fn clone(&self) -> Runtime

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
source§

impl Send for Runtime

source§

impl Sync for Runtime

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
where T: Send,