Struct trillium_router::RouterRef[][src]

pub struct RouterRef<'r>(_);
Expand description

A &mut Router for use with Router::build

A wrapper around a &mut Router that supports imperative route registration. See Router::build for further documentation.

Implementations

Registers a handler for the get http method.

let router = Router::build(|mut router| {
    router.get("/some/route", |conn: Conn| async move {
        conn.ok("success")
    });
});

use trillium_testing::{methods::get, assert_ok, assert_not_handled};
assert_ok!(get("/some/route").on(&router), "success");
assert_not_handled!(get("/other/route").on(&router));

Registers a handler for the post http method.

let router = Router::build(|mut router| {
    router.post("/some/route", |conn: Conn| async move {
        conn.ok("success")
    });
});

use trillium_testing::{methods::post, assert_ok, assert_not_handled};
assert_ok!(post("/some/route").on(&router), "success");
assert_not_handled!(post("/other/route").on(&router));

Registers a handler for the put http method.

let router = Router::build(|mut router| {
    router.put("/some/route", |conn: Conn| async move {
        conn.ok("success")
    });
});

use trillium_testing::{methods::put, assert_ok, assert_not_handled};
assert_ok!(put("/some/route").on(&router), "success");
assert_not_handled!(put("/other/route").on(&router));

Registers a handler for the delete http method.

let router = Router::build(|mut router| {
    router.delete("/some/route", |conn: Conn| async move {
        conn.ok("success")
    });
});

use trillium_testing::{methods::delete, assert_ok, assert_not_handled};
assert_ok!(delete("/some/route").on(&router), "success");
assert_not_handled!(delete("/other/route").on(&router));

Registers a handler for the patch http method.

let router = Router::build(|mut router| {
    router.patch("/some/route", |conn: Conn| async move {
        conn.ok("success")
    });
});

use trillium_testing::{methods::patch, assert_ok, assert_not_handled};
assert_ok!(patch("/some/route").on(&router), "success");
assert_not_handled!(patch("/other/route").on(&router));

Appends the handler to all (get, post, put, delete, and patch) methods.

let router = Router::build(|mut router| {
    router.any("/any", |conn: Conn| async move {
        let response = format!("you made a {} request to /any", conn.method());
        conn.ok(response)
    });
});

use trillium_testing::prelude::*;
assert_ok!(get("/any").on(&router), "you made a GET request to /any");
assert_ok!(post("/any").on(&router), "you made a POST request to /any");
assert_ok!(delete("/any").on(&router), "you made a DELETE request to /any");
assert_ok!(patch("/any").on(&router), "you made a PATCH request to /any");
assert_ok!(put("/any").on(&router), "you made a PUT request to /any");

assert_not_handled!(get("/").on(&router));

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.