worker_route

Trait Configure

Source
pub trait Configure<D> {
    // Required method
    fn configure<F: RouteFactory<D>>(self, f: F) -> Self;
}
Expand description

Implemented for worker::Router to configure the route’s pattern.

§Example

use serde::{Deserialize, Serialize};
use worker::{event, Env, Request, Response, ResponseBody, Result, RouteContext, Router};
use worker_route::{get, Configure, Query, Service};

#[derive(Debug, Deserialize, Serialize)]
struct Person {
    name: String,
    age: usize,
}

#[get("/person/:name/:age")]
async fn person(req: Query<Person>, _: RouteContext<()>) -> Result<Response> {
    Response::from_json(&req.into_inner())
}

#[event(fetch)]
pub async fn main(req: Request, env: Env, _ctx: worker::Context) -> Result<Response> {
    let router = Router::new();
    router.configure(person).run(req, env).await
}

Required Methods§

Source

fn configure<F: RouteFactory<D>>(self, f: F) -> Self

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.

Implementations on Foreign Types§

Source§

impl<D> Configure<D> for Router<'_, D>

Source§

fn configure<F: RouteFactory<D>>(self, f: F) -> Self

Implementors§