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>
impl<'a> Router<'a>
Sourcepub fn new(prefix: &'a str) -> Self
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
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}
Sourcepub fn get(
&mut self,
path: &'a str,
func: fn(&mut Context<'_>, &mut dyn FnMut(&mut Context<'_>)),
)
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
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}
pub fn post( &mut self, path: &'a str, func: fn(&mut Context<'_>, &mut dyn FnMut(&mut Context<'_>)), )
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more