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
sourceimpl 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
let ctx = ExecuteCtx::new("path/to/a/file.wasm")?;
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
sourceimpl<'addr> Service<&'addr AddrStream> for ViceroyService
impl<'addr> Service<&'addr AddrStream> for ViceroyService
type Response = RequestService
type Response = RequestService
Responses given by the service.
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.
sourcefn 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 more
sourcefn 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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
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.
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,
Create a new SetFdFlags
value for use with set_fd_flags
. Read more
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
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<T> Pointable for T
impl<T> Pointable for T
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more