Struct Router

Source
pub struct Router<'a> {
    pub prefix: &'a str,
    pub layers: Vec<Handler>,
}

Fields§

§prefix: &'a str§layers: Vec<Handler>

Implementations§

Source§

impl<'a> Router<'a>

Source

pub fn new(prefix: &'a str) -> Self

Examples found in repository?
examples/router.rs (line 9)
6fn main() {
7    let mut app = Aero::new("127.0.0.1:3000");
8
9    let mut router = Router::new("/api");
10    router.get("/book", |ctx: &mut Context, next: Next| {
11        ctx.send_text("hello, is's /api/book");
12        next(ctx);
13    });
14
15    app.mount(router);
16
17    println!("Listening on http://{}", app.socket_addr);
18
19    tokio::runtime::Builder::new_multi_thread()
20        // .worker_threads(6)
21        .enable_all()
22        .build()
23        .unwrap()
24        .block_on(app.run());
25}
More examples
Hide additional examples
examples/json.rs (line 18)
15fn main() {
16    let mut app = Aero::new("127.0.0.1:3000");
17
18    let mut router = Router::new("/api");
19    router.get("/book", |ctx: &mut Context, next: Next| {
20        ctx.send_json(Book {
21            id: 123,
22            name: "asd".to_string(),
23            price: 123.3,
24        });
25        next(ctx);
26    });
27    app.mount(router);
28
29    app.get("/hello", |ctx: &mut Context, next: Next| {
30        ctx.send_text("Hello, world!");
31    });
32
33    println!("Listening on http://{}", app.socket_addr);
34
35    tokio::runtime::Builder::new_multi_thread()
36        // .worker_threads(6)
37        .enable_all()
38        .build()
39        .unwrap()
40        .block_on(app.run());
41}
Source

pub fn get( &mut self, path: &'a str, func: fn(&mut Context<'_>, &mut dyn FnMut(&mut Context<'_>)), )

Examples found in repository?
examples/router.rs (lines 10-13)
6fn main() {
7    let mut app = Aero::new("127.0.0.1:3000");
8
9    let mut router = Router::new("/api");
10    router.get("/book", |ctx: &mut Context, next: Next| {
11        ctx.send_text("hello, is's /api/book");
12        next(ctx);
13    });
14
15    app.mount(router);
16
17    println!("Listening on http://{}", app.socket_addr);
18
19    tokio::runtime::Builder::new_multi_thread()
20        // .worker_threads(6)
21        .enable_all()
22        .build()
23        .unwrap()
24        .block_on(app.run());
25}
More examples
Hide additional examples
examples/json.rs (lines 19-26)
15fn main() {
16    let mut app = Aero::new("127.0.0.1:3000");
17
18    let mut router = Router::new("/api");
19    router.get("/book", |ctx: &mut Context, next: Next| {
20        ctx.send_json(Book {
21            id: 123,
22            name: "asd".to_string(),
23            price: 123.3,
24        });
25        next(ctx);
26    });
27    app.mount(router);
28
29    app.get("/hello", |ctx: &mut Context, next: Next| {
30        ctx.send_text("Hello, world!");
31    });
32
33    println!("Listening on http://{}", app.socket_addr);
34
35    tokio::runtime::Builder::new_multi_thread()
36        // .worker_threads(6)
37        .enable_all()
38        .build()
39        .unwrap()
40        .block_on(app.run());
41}
Source

pub fn post( &mut self, path: &'a str, func: fn(&mut Context<'_>, &mut dyn FnMut(&mut Context<'_>)), )

Source

pub fn hold( &mut self, path: &'a str, func: fn(&mut Context<'_>, &mut dyn FnMut(&mut Context<'_>)), )

Auto Trait Implementations§

§

impl<'a> Freeze for Router<'a>

§

impl<'a> RefUnwindSafe for Router<'a>

§

impl<'a> Send for Router<'a>

§

impl<'a> Sync for Router<'a>

§

impl<'a> Unpin for Router<'a>

§

impl<'a> UnwindSafe for Router<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.