---
title: Serve
summary: Support for processing multiple requests from a single sandbox.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/serve/struct.Serve/
---

**Kind:** Struct  
**Module:** [serve](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/serve/)  
**Package:** fastly 0.13.1  
**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#230

```rust
pub struct Serve { /* private fields */ }
```

Support for processing multiple requests from a single sandbox.

## Methods

### new

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#240

```rust
fn new() -> Self
```

Prepare a new [Serve](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/serve/struct.Serve/) instance for handling requests in this sandbox.

**Returns**

`Self`

### run

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#284

```rust
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

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#299

```rust
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](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/http/serve/trait.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

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#253

```rust
fn with_max_lifetime(self, limit: Duration) -> Self
```

Configure when to stop accepting additional requests.

Defaults to [Duration::MAX](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#associatedconstant.MAX).

**Parameters**

- `self`: `Self`
- `limit`: `Duration`

**Returns**

`Self`

### with_max_memory

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#262

```rust
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 [heap_memory_snapshot_mib](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/compute_runtime/fn.heap_memory_snapshot_mib/).

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

**Parameters**

- `self`: `Self`
- `mib`: `u32`

**Returns**

`Self`

### with_max_requests

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#270

```rust
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

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#278

```rust
fn with_timeout(self, timeout: Duration) -> Self
```

Configure how long to wait for another request before stopping.

Defaults to [Duration::MAX](https://doc.rust-lang.org/stable/core/time/struct.Duration.html#associatedconstant.MAX).

**Parameters**

- `self`: `Self`
- `timeout`: `Duration`

**Returns**

`Self`

## Trait implementations

### impl Default for Serve

#### default

**Source:** https://docs.rs/crate/fastly/0.13.1/source/src/http/serve.rs#372

```rust
fn default() -> Self
```

**Returns**

`Self`

## Auto trait implementations

- `Freeze`
- `RefUnwindSafe`
- `Send`
- `Sync`
- `Unpin`
- `UnsafeUnpin`
- `UnwindSafe`

## Blanket implementations

- `Any`
- `Borrow<T>`
- `BorrowMut<T>`
- `Downcast`
- `DowncastSync`
- `ErasedDestructor`
- `From<T>`
- `Into<U>`
- `IntoEither`
- `Same`
- `TryFrom<U>`
- `TryInto<U>`
