worker_route

Trait Wrap

Source
pub trait Wrap {
    type Output;

    // Required method
    fn wrap(req: &Request) -> Self::Output;
}
Expand description

A handler middleware provides an access to worker::Request

Currently this is only used to return Cors

§Examples

use worker::{Cors, Request, Response, Result, RouteContext};
use worker_route::{route, Wrap};

// Doesn't necessarily have to be a unit struct.
// It can be anything.
pub struct MyCors;

impl Wrap for MyCors {
    type Output = Cors;

    fn wrap(req: &Request) -> Self::Output {
        Cors::default()
    }
}

#[route("/hello-world", method = "get", cors = MyCors)]
fn hello_world(req: Request, ctx: RouteContext<()>) -> Result<String> {
    Ok("Hello world.".to_owned())
}

Required Associated Types§

Source

type Output

The output of the return value.

Required Methods§

Source

fn wrap(req: &Request) -> Self::Output

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§