Struct viceroy_lib::ExecuteCtx
source · pub struct ExecuteCtx { /* private fields */ }
Expand description
Execution context used by a ViceroyService
.
This is all of the state needed to instantiate a module, in order to respond to an HTTP
request. Note that it is very important that ExecuteCtx
be cheaply clonable, as it is cloned
every time that a viceroy service handles an incoming connection.
Implementations§
source§impl ExecuteCtx
impl ExecuteCtx
sourcepub fn new(
module_path: impl AsRef<Path>,
profiling_strategy: ProfilingStrategy,
wasi_modules: HashSet<ExperimentalModule>,
guest_profile_path: Option<PathBuf>,
unknown_import_behavior: UnknownImportBehavior
) -> Result<Self, Error>
pub fn new( module_path: impl AsRef<Path>, profiling_strategy: ProfilingStrategy, wasi_modules: HashSet<ExperimentalModule>, guest_profile_path: Option<PathBuf>, unknown_import_behavior: UnknownImportBehavior ) -> Result<Self, Error>
Create a new execution context, given the path to a module and a set of experimental wasi modules.
sourcepub fn with_backends(self, backends: Backends) -> Self
pub fn with_backends(self, backends: Backends) -> Self
Set the backends for this execution context.
sourcepub fn device_detection(&self) -> &DeviceDetection
pub fn device_detection(&self) -> &DeviceDetection
Get the device detection mappings for this execution context.
sourcepub fn with_device_detection(self, device_detection: DeviceDetection) -> Self
pub fn with_device_detection(self, device_detection: DeviceDetection) -> Self
Set the device detection mappings for this execution context.
sourcepub fn geolocation(&self) -> &Geolocation
pub fn geolocation(&self) -> &Geolocation
Get the geolocation mappings for this execution context.
sourcepub fn with_geolocation(self, geolocation: Geolocation) -> Self
pub fn with_geolocation(self, geolocation: Geolocation) -> Self
Set the geolocation mappings for this execution context.
sourcepub fn dictionaries(&self) -> &Dictionaries
pub fn dictionaries(&self) -> &Dictionaries
Get the dictionaries for this execution context.
sourcepub fn with_dictionaries(self, dictionaries: Dictionaries) -> Self
pub fn with_dictionaries(self, dictionaries: Dictionaries) -> Self
Set the dictionaries for this execution context.
sourcepub fn with_object_stores(self, object_store: ObjectStores) -> Self
pub fn with_object_stores(self, object_store: ObjectStores) -> Self
Set the object store for this execution context.
sourcepub fn with_secret_stores(self, secret_stores: SecretStores) -> Self
pub fn with_secret_stores(self, secret_stores: SecretStores) -> Self
Set the secret stores for this execution context.
sourcepub fn with_config_path(self, config_path: PathBuf) -> Self
pub fn with_config_path(self, config_path: PathBuf) -> Self
Set the path to the config for this execution context.
sourcepub fn log_stdout(&self) -> bool
pub fn log_stdout(&self) -> bool
Whether to treat stdout as a logging endpoint.
sourcepub fn with_log_stdout(self, log_stdout: bool) -> Self
pub fn with_log_stdout(self, log_stdout: bool) -> Self
Set the stdout logging policy for this execution context.
sourcepub fn log_stderr(&self) -> bool
pub fn log_stderr(&self) -> bool
Whether to treat stderr as a logging endpoint.
sourcepub fn with_log_stderr(self, log_stderr: bool) -> Self
pub fn with_log_stderr(self, log_stderr: bool) -> Self
Set the stderr logging policy for this execution context.
sourcepub fn tls_config(&self) -> &TlsConfig
pub fn tls_config(&self) -> &TlsConfig
Gets the TLS configuration
sourcepub async fn handle_request(
self,
incoming_req: Request<Body>,
remote: IpAddr
) -> Result<(Response<Body>, Option<Error>), Error>
pub async fn handle_request( self, incoming_req: Request<Body>, remote: IpAddr ) -> Result<(Response<Body>, Option<Error>), Error>
Asynchronously handle a request.
This method fully instantiates the wasm module housed within the ExecuteCtx
,
including running the wasm start function. It then proceeds to execute the
instantiated module’s WASI entry point, running to completion. If execution
results in an error, a response is still produced, but with a 500 status code.
Build time: Before you build or test your code, we recommend to set the release flag
e.g. cargo test --release
otherwise the execution will be very slow. This has to do
with the Cranelift compiler, which is extremely slow when compiled in debug mode.
§Example
use hyper::{Body, http::Request};
let ctx = ExecuteCtx::new("path/to/a/file.wasm", ProfilingStrategy::None, HashSet::new(), None, Default::default())?;
let resp = ctx.handle_request(req, "127.0.0.1".parse().unwrap()).await?;
pub async fn handle_request_with_runtime_error( self, incoming_req: Request<Body>, remote: IpAddr ) -> Result<Response<Body>, Error>
pub async fn run_main( self, program_name: &str, args: &[String] ) -> Result<(), Error>
Trait Implementations§
source§impl Clone for ExecuteCtx
impl Clone for ExecuteCtx
source§fn clone(&self) -> ExecuteCtx
fn clone(&self) -> ExecuteCtx
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations§
impl Freeze for ExecuteCtx
impl !RefUnwindSafe for ExecuteCtx
impl Send for ExecuteCtx
impl Sync for ExecuteCtx
impl Unpin for ExecuteCtx
impl !UnwindSafe for ExecuteCtx
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> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
source§fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
fn get_fd_flags(&self) -> Result<FdFlags, Error>where
T: AsFilelike,
self
file descriptor.source§fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
fn new_set_fd_flags(&self, fd_flags: FdFlags) -> Result<SetFdFlags<T>, Error>where
T: AsFilelike,
source§fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
fn set_fd_flags(&mut self, set_fd_flags: SetFdFlags<T>) -> Result<(), Error>where
T: AsFilelike,
self
file descriptor. Read more