Struct viceroy_lib::ViceroyService
source · pub struct ViceroyService { /* private fields */ }
Expand description
A Viceroy service uses a Wasm module and a handler function to respond to HTTP requests.
This service type is used to compile a Wasm Module
, and perform the actions necessary
to initialize a Server
and bind the service to a local port.
Each time a connection is received, a RequestService
will be created, to
instantiate the module and return a Response
.
Implementations§
source§impl ViceroyService
impl ViceroyService
sourcepub fn new(ctx: ExecuteCtx) -> Self
pub fn new(ctx: ExecuteCtx) -> Self
Create a new Viceroy service, using the given handler function and module path.
Example
use viceroy_lib::{Error, ExecuteCtx, ProfilingStrategy, ViceroyService};
let ctx = ExecuteCtx::new("path/to/a/file.wasm", ProfilingStrategy::None, HashSet::new())?;
let svc = ViceroyService::new(ctx);
sourcepub async fn serve(self, addr: SocketAddr) -> Result<(), Error>
pub async fn serve(self, addr: SocketAddr) -> Result<(), Error>
Bind this service to the given address and start serving responses.
This will consume the service, using it to start a server that will execute the given module each time a new request is sent. This function will only return if an error occurs.
Trait Implementations§
source§impl<'addr> Service<&'addr AddrStream> for ViceroyService
impl<'addr> Service<&'addr AddrStream> for ViceroyService
§type Error = Infallible
type Error = Infallible
Errors produced by the service.
§type Future = Ready<Result<<ViceroyService as Service<&'addr AddrStream>>::Response, <ViceroyService as Service<&'addr AddrStream>>::Error>>
type Future = Ready<Result<<ViceroyService as Service<&'addr AddrStream>>::Response, <ViceroyService as Service<&'addr AddrStream>>::Error>>
The future response value.
source§fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
fn poll_ready(&mut self, _cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>>
Returns
Poll::Ready(Ok(()))
when the service is able to process requests. Read moresource§fn call(&mut self, addr: &'addr AddrStream) -> Self::Future
fn call(&mut self, addr: &'addr AddrStream) -> Self::Future
Process the request and return the response asynchronously. Read more
Auto Trait Implementations§
impl !RefUnwindSafe for ViceroyService
impl Send for ViceroyService
impl Sync for ViceroyService
impl Unpin for ViceroyService
impl !UnwindSafe for ViceroyService
Blanket Implementations§
§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,
Query the “status” flags for the
self
file descriptor.