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
sourceimpl ExecuteCtx
impl ExecuteCtx
sourcepub fn new(
module_path: impl AsRef<Path>,
profiling_strategy: ProfilingStrategy
) -> Result<Self, Error>
pub fn new(
module_path: impl AsRef<Path>,
profiling_strategy: ProfilingStrategy
) -> Result<Self, Error>
Create a new execution context, given the path to a module.
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 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_store(self, object_store: ObjectStore) -> Self
pub fn with_object_store(self, object_store: ObjectStore) -> Self
Set the object store 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>, Error>
pub async fn handle_request(
self,
incoming_req: Request<Body>,
remote: IpAddr
) -> Result<Response<Body>, 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
let ctx = ExecuteCtx::new("path/to/a/file.wasm", ProfilingStrategy::None)?;
let resp = ctx.handle_request(req, "127.0.0.1".parse().unwrap()).await?;
Trait Implementations
sourceimpl Clone for ExecuteCtx
impl Clone for ExecuteCtx
sourcefn clone(&self) -> ExecuteCtx
fn clone(&self) -> ExecuteCtx
1.0.0 · sourceconst fn clone_from(&mut self, source: &Self)
const fn clone_from(&mut self, source: &Self)
source
. Read moreAuto Trait Implementations
impl !RefUnwindSafe for ExecuteCtx
impl Send for ExecuteCtx
impl Sync for ExecuteCtx
impl Unpin for ExecuteCtx
impl !UnwindSafe for ExecuteCtx
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<T> GetSetFdFlags for T
impl<T> GetSetFdFlags for T
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.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,
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