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(), None, Default::default())?;
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.
Auto Trait Implementations§
impl Freeze for ViceroyService
impl !RefUnwindSafe for ViceroyService
impl Send for ViceroyService
impl Sync for ViceroyService
impl Unpin for ViceroyService
impl !UnwindSafe for ViceroyService
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
Mutably borrows from an owned value. Read more
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,
Query the “status” flags for the
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,
Set the “status” flags for the
self
file descriptor. Read more