Serve

Structin servefastly 0.13.1View source
pub struct Serve { /* private fields */ }

Support for processing multiple requests from a single sandbox.

Methods

fn new() -> Self

Prepare a new Serve instance for handling requests in this sandbox.

Returns

Self
fn run<F, MaybeResult>(self, handler: F) -> ServeSummary<MaybeResult::Error>
where
F: FnMut(Request) -> MaybeResult,
MaybeResult: HandlerResult,

Begin serving requests in this sandbox.

Parameters

self: Self
handler: F

Returns

ServeSummary<MaybeResult::Error>

run_with_context

View source
fn run_with_context<F, C, MaybeResult>(self, handler: F, cx: &mut C) -> ServeSummary<MaybeResult::Error>
where
F: FnMut(Request, &mut C) -> MaybeResult,
MaybeResult: HandlerResult,

Begin serving requests in this sandbox, but with a contextual argument passed to every invocation of the handler callback.

The callback should return a type that implements HandlerResult, such as:

  • Response, if it always returns a response.
  • Result<Response, E>, if it might fail with an error of type E instead of generating a response

Parameters

self: Self
handler: F
cx: &mut C

Returns

ServeSummary<MaybeResult::Error>

with_max_lifetime

View source
fn with_max_lifetime(self, limit: Duration) -> Self

Configure when to stop accepting additional requests.

Defaults to Duration::MAX.

Parameters

self: Self
limit: Duration

Returns

Self

with_max_memory

View source
fn with_max_memory(self, mib: u32) -> Self

Configure the maximum amount of memory (in mebibytes) to allow this instance to use before stopping, as reported by heapmemorysnapshot_mib.

A limit of 0 (the default) will be treated as unlimited.

Parameters

self: Self
mib: u32

Returns

Self

with_max_requests

View source
fn with_max_requests(self, limit: usize) -> Self

Configure the maximum number of requests to serve before stopping.

A limit of 0 (the default) will be treated as unlimited.

Parameters

self: Self
limit: usize

Returns

Self

with_timeout

View source
fn with_timeout(self, timeout: Duration) -> Self

Configure how long to wait for another request before stopping.

Defaults to Duration::MAX.

Parameters

self: Self
timeout: Duration

Returns

Self

Trait implementations

impl Default for Serve

fn default() -> Self

Returns

Self

Auto trait implementations

Blanket implementations