---
title: main
summary: Main function attribute for a Compute program.
url: https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/attr.main/
---

**Kind:** Attribute macro  
**Module:** [fastly](https://www.fastly.com/documentation/reference/compute/sdks/rust/fastly/)  
**Package:** fastly 0.13.1

```rust
#[main]
```

Main function attribute for a Compute program.

### Usage

This attribute should be applied to a `main` function that takes a request and returns a
response or an error. For example:

```rust
use fastly::{Error, Request, Response};

#[fastly::main]
fn main(ds_req: Request) -> Result<Response, Error> {
    Ok(ds_req.send("example_backend")?)
}
```

You can apply `#[fastly::main]` to any function that takes `Request` as its sole argument, and
returns a `Result<Response, Error>`.

### More Information

This is a convenience to abstract over the common usage of `Request::from_client()` and
`Response::send_to_client()` at the beginning and end of a program's `main()` function. The
macro use above is equivalent to the following code:

```rust
use fastly::{Error, Request};

fn main() -> Result<(), Error> {
    let ds_req = Request::from_client();
    let us_resp = ds_req.send("example_backend")?;
    us_resp.send_to_client();
    Ok(())
}
```
