pub struct RuntimeBuilder(/* private fields */);
Expand description
A builder for creating a new runtime
Just a helper wrapper around RuntimeOptions
for Runtime
and SnapshotBuilder
§Example
use rustyscript::RuntimeBuilder;
let runtime = RuntimeBuilder::new()
.with_timeout(std::time::Duration::from_secs(5))
.with_default_entrypoint("main".to_string())
.with_cryto_seed(42)
.build()
.expect("Failed to create runtime");
Implementations§
Source§impl RuntimeBuilder
impl RuntimeBuilder
Sourcepub fn with_extension(self, extension: Extension) -> Self
pub fn with_extension(self, extension: Extension) -> Self
Add an extension to the runtime
This can be used to add custom functionality to the runtime
If the extension is for use with a snapshot, create the extension with init_ops
instead of init_ops_and_esm
Sourcepub fn with_extensions(self, extensions: Vec<Extension>) -> Self
pub fn with_extensions(self, extensions: Vec<Extension>) -> Self
Add multiple extensions to the runtime
This can be used to add custom functionality to the runtime
If the extension is for use with a snapshot, create the extension with init_ops
instead of init_ops_and_esm
Sourcepub fn with_default_entrypoint(self, entrypoint: String) -> Self
pub fn with_default_entrypoint(self, entrypoint: String) -> Self
Set the default entrypoint for the runtime
This is the function to use as entrypoint if a module does not provide one
Sourcepub fn with_timeout(self, timeout: Duration) -> Self
pub fn with_timeout(self, timeout: Duration) -> Self
Set the timeout for the runtime
This is the maximum time a script can run before it is terminated
Sourcepub fn with_max_heap_size(self, max_heap_size: usize) -> Self
pub fn with_max_heap_size(self, max_heap_size: usize) -> Self
Optional maximum heap size for the runtime
Sourcepub fn with_import_provider(
self,
import_provider: Box<dyn ImportProvider>,
) -> Self
pub fn with_import_provider( self, import_provider: Box<dyn ImportProvider>, ) -> Self
Optional import provider for the module loader
Sourcepub fn with_startup_snapshot(self, snapshot: &'static [u8]) -> Self
pub fn with_startup_snapshot(self, snapshot: &'static [u8]) -> Self
Set the startup snapshot for the runtime
This will reduce load times, but requires the same extensions to be loaded as when the snapshot was created
If provided, user-supplied extensions must be instantiated with init_ops
instead of init_ops_and_esm
WARNING: Snapshots MUST be used on the same system they were created on
Sourcepub fn with_isolate_params(self, params: CreateParams) -> Self
pub fn with_isolate_params(self, params: CreateParams) -> Self
Set the params used to create the underlying V8 isolate
This can be used to alter the behavior of the runtime.
See the rusty_v8
documentation for more information
Set the shared array buffer store to use for the runtime
Allows data-sharing between runtimes across threads
Sourcepub fn with_schema(self, schema: impl ToString) -> Self
pub fn with_schema(self, schema: impl ToString) -> Self
Add to a whitelist of custom schema prefixes that are allowed to be loaded from javascript
By default only http/https (url_import
crate feature), and file (fs_import
crate feature) are allowed
Sourcepub fn with_cryto_seed(self, seed: u64) -> Self
Available on crate feature crypto
only.
pub fn with_cryto_seed(self, seed: u64) -> Self
crypto
only.Set the initial seed for the crypto extension
Sourcepub fn with_io_pipes(self, pipes: Stdio) -> Self
Available on crate feature io
only.
pub fn with_io_pipes(self, pipes: Stdio) -> Self
io
only.Set the options for the io extension
Sourcepub fn with_webstorage_origin_storage_dir(self, dir: PathBuf) -> Self
Available on crate feature webstorage
only.
pub fn with_webstorage_origin_storage_dir(self, dir: PathBuf) -> Self
webstorage
only.Set the options for the webstorage extension
Sourcepub fn with_cache(self, cache: CreateCache<CacheBackend>) -> Self
Available on crate feature cache
only.
pub fn with_cache(self, cache: CreateCache<CacheBackend>) -> Self
cache
only.Set the options for the cache extension
Sourcepub fn with_broadcast_channel(self, channel: InMemoryBroadcastChannel) -> Self
Available on crate feature broadcast_channel
only.
pub fn with_broadcast_channel(self, channel: InMemoryBroadcastChannel) -> Self
broadcast_channel
only.Set the options for the broadcast channel extension
Sourcepub fn with_kv_store(self, kv_store: KvStore) -> Self
Available on crate feature kv
only.
pub fn with_kv_store(self, kv_store: KvStore) -> Self
kv
only.Set the options for the kv store extension
Sourcepub fn with_node_resolver(self, resolver: Arc<RustyResolver>) -> Self
Available on crate feature node_experimental
only.
pub fn with_node_resolver(self, resolver: Arc<RustyResolver>) -> Self
node_experimental
only.Set the options for the node extension
Sourcepub fn with_web_base_url(self, base_url: ModuleSpecifier) -> Self
Available on crate feature web
only.
pub fn with_web_base_url(self, base_url: ModuleSpecifier) -> Self
web
only.Base URL for some deno_web
OPs
Sourcepub fn with_web_user_agent(self, user_agent: String) -> Self
Available on crate feature web
only.
pub fn with_web_user_agent(self, user_agent: String) -> Self
web
only.User agent to use for fetch
Sourcepub fn with_web_root_cert_store_provider(
self,
root_cert_store_provider: Arc<dyn RootCertStoreProvider>,
) -> Self
Available on crate feature web
only.
pub fn with_web_root_cert_store_provider( self, root_cert_store_provider: Arc<dyn RootCertStoreProvider>, ) -> Self
web
only.Root certificate store for TLS connections for fetches and network OPs
Sourcepub fn with_web_proxy(self, proxy: Proxy) -> Self
Available on crate feature web
only.
pub fn with_web_proxy(self, proxy: Proxy) -> Self
web
only.Proxy for fetch
Sourcepub fn with_web_request_builder_hook(
self,
hook: fn(&mut Request<ReqBody>) -> Result<(), AnyError>,
) -> Self
Available on crate feature web
only.
pub fn with_web_request_builder_hook( self, hook: fn(&mut Request<ReqBody>) -> Result<(), AnyError>, ) -> Self
web
only.Request builder hook for fetch
Sourcepub fn with_web_unsafely_ignored_certificate_errors(
self,
domain: impl ToString,
) -> Self
Available on crate feature web
only.
pub fn with_web_unsafely_ignored_certificate_errors( self, domain: impl ToString, ) -> Self
web
only.List of domain names or IP addresses for which fetches and network OPs will ignore SSL errors
This is useful for testing with self-signed certificates
Sourcepub fn with_web_client_cert_chain_and_key(self, keys: TlsKeys) -> Self
Available on crate feature web
only.
pub fn with_web_client_cert_chain_and_key(self, keys: TlsKeys) -> Self
web
only.Client certificate and key for fetch
Sourcepub fn with_web_file_fetch_handler(self, handler: Rc<dyn FetchHandler>) -> Self
Available on crate feature web
only.
pub fn with_web_file_fetch_handler(self, handler: Rc<dyn FetchHandler>) -> Self
web
only.File fetch handler for fetch
Sourcepub fn with_web_permissions(self, permissions: Arc<dyn WebPermissions>) -> Self
Available on crate feature web
only.
pub fn with_web_permissions(self, permissions: Arc<dyn WebPermissions>) -> Self
web
only.Permissions manager for sandbox-breaking extensions
Sourcepub fn with_web_blob_store(self, blob_store: Arc<BlobStore>) -> Self
Available on crate feature web
only.
pub fn with_web_blob_store(self, blob_store: Arc<BlobStore>) -> Self
web
only.Blob store for the web related extensions
Sourcepub fn with_web_client_builder_hook(
self,
hook: Option<fn(Builder) -> Builder>,
) -> Self
Available on crate feature web
only.
pub fn with_web_client_builder_hook( self, hook: Option<fn(Builder) -> Builder>, ) -> Self
web
only.A callback to customize HTTP client configuration.
For more info on what can be configured, see hyper_util::client::legacy::Builder
Sourcepub fn with_web_resolver(self, resolver: Resolver) -> Self
Available on crate feature web
only.
pub fn with_web_resolver(self, resolver: Resolver) -> Self
web
only.Resolver for DNS resolution
Sourcepub fn build(self) -> Result<Runtime, Error>
pub fn build(self) -> Result<Runtime, Error>
Consume the builder and create a new runtime with the given options
§Errors
Will return an error if the runtime cannot be created (usually an issue with extensions)
Sourcepub fn build_snapshot(self) -> Result<SnapshotBuilder, Error>
Available on crate feature snapshot_builder
only.
pub fn build_snapshot(self) -> Result<SnapshotBuilder, Error>
snapshot_builder
only.Consume the builder and create a new snapshot runtime with the given options
§Errors
Will return an error if the runtime cannot be created (usually an issue with extensions)
Trait Implementations§
Auto Trait Implementations§
impl Freeze for RuntimeBuilder
impl !Send for RuntimeBuilder
impl !Sync for RuntimeBuilder
impl !RefUnwindSafe for RuntimeBuilder
impl Unpin for RuntimeBuilder
impl !UnwindSafe for RuntimeBuilder
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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> CheckedAs for T
impl<T> CheckedAs for T
Source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
Source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
Source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request
Source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
Source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
Source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
Source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
Source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
Source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
Source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.