pub struct ErrorRouter { /* private fields */ }
Implementations§
Source§impl ErrorRouter
impl ErrorRouter
Sourcepub fn new() -> Self
pub fn new() -> Self
Examples found in repository?
examples/basic.rs (line 14)
7fn main() {
8 let handler = |_: &mut Request| {
9 Ok(Response::with((status::NotFound)))
10 };
11
12 let mut chain = Chain::new(handler);
13 chain.link_after({
14 let mut error_router = iron_error_router::ErrorRouter::new();
15
16 // In case the response is a 404, replace the response with your own.
17
18 error_router.handle_status(status::NotFound, |_: &mut Request| {
19 Ok(Response::with((
20 status::NotFound,
21 "Content not found."
22 )))
23 });
24
25 // Instead of writing a handler, you can just use a modifier:
26
27 error_router.modifier_for_status(
28 status::NotFound,
29 (status::NotFound, "Content not found.")
30 );
31
32 // Or an AfterMiddleware:
33
34 error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35 Ok(Response::with((status::NotFound, "Content not found.")))
36 });
37
38 error_router
39 });
40
41 Iron::new(chain).http("localhost:3000").unwrap();
42}
Sourcepub fn handle_status<T: Handler>(&mut self, status: Status, handler: T)
pub fn handle_status<T: Handler>(&mut self, status: Status, handler: T)
Examples found in repository?
examples/basic.rs (lines 18-23)
7fn main() {
8 let handler = |_: &mut Request| {
9 Ok(Response::with((status::NotFound)))
10 };
11
12 let mut chain = Chain::new(handler);
13 chain.link_after({
14 let mut error_router = iron_error_router::ErrorRouter::new();
15
16 // In case the response is a 404, replace the response with your own.
17
18 error_router.handle_status(status::NotFound, |_: &mut Request| {
19 Ok(Response::with((
20 status::NotFound,
21 "Content not found."
22 )))
23 });
24
25 // Instead of writing a handler, you can just use a modifier:
26
27 error_router.modifier_for_status(
28 status::NotFound,
29 (status::NotFound, "Content not found.")
30 );
31
32 // Or an AfterMiddleware:
33
34 error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35 Ok(Response::with((status::NotFound, "Content not found.")))
36 });
37
38 error_router
39 });
40
41 Iron::new(chain).http("localhost:3000").unwrap();
42}
Sourcepub fn after_status<T: AfterMiddleware>(
&mut self,
status: Status,
middleware: T,
)
pub fn after_status<T: AfterMiddleware>( &mut self, status: Status, middleware: T, )
Examples found in repository?
examples/basic.rs (lines 34-36)
7fn main() {
8 let handler = |_: &mut Request| {
9 Ok(Response::with((status::NotFound)))
10 };
11
12 let mut chain = Chain::new(handler);
13 chain.link_after({
14 let mut error_router = iron_error_router::ErrorRouter::new();
15
16 // In case the response is a 404, replace the response with your own.
17
18 error_router.handle_status(status::NotFound, |_: &mut Request| {
19 Ok(Response::with((
20 status::NotFound,
21 "Content not found."
22 )))
23 });
24
25 // Instead of writing a handler, you can just use a modifier:
26
27 error_router.modifier_for_status(
28 status::NotFound,
29 (status::NotFound, "Content not found.")
30 );
31
32 // Or an AfterMiddleware:
33
34 error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35 Ok(Response::with((status::NotFound, "Content not found.")))
36 });
37
38 error_router
39 });
40
41 Iron::new(chain).http("localhost:3000").unwrap();
42}
Sourcepub fn modifier_for_status<T: Modifier<Response> + Send + Sync + Clone + 'static>(
&mut self,
status: Status,
modifier: T,
)
pub fn modifier_for_status<T: Modifier<Response> + Send + Sync + Clone + 'static>( &mut self, status: Status, modifier: T, )
Examples found in repository?
examples/basic.rs (lines 27-30)
7fn main() {
8 let handler = |_: &mut Request| {
9 Ok(Response::with((status::NotFound)))
10 };
11
12 let mut chain = Chain::new(handler);
13 chain.link_after({
14 let mut error_router = iron_error_router::ErrorRouter::new();
15
16 // In case the response is a 404, replace the response with your own.
17
18 error_router.handle_status(status::NotFound, |_: &mut Request| {
19 Ok(Response::with((
20 status::NotFound,
21 "Content not found."
22 )))
23 });
24
25 // Instead of writing a handler, you can just use a modifier:
26
27 error_router.modifier_for_status(
28 status::NotFound,
29 (status::NotFound, "Content not found.")
30 );
31
32 // Or an AfterMiddleware:
33
34 error_router.after_status(status::NotFound, |_: &mut Request, _: Response| {
35 Ok(Response::with((status::NotFound, "Content not found.")))
36 });
37
38 error_router
39 });
40
41 Iron::new(chain).http("localhost:3000").unwrap();
42}
Trait Implementations§
Source§impl AfterMiddleware for ErrorRouter
impl AfterMiddleware for ErrorRouter
Source§impl Default for ErrorRouter
impl Default for ErrorRouter
Source§fn default() -> ErrorRouter
fn default() -> ErrorRouter
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for ErrorRouter
impl !RefUnwindSafe for ErrorRouter
impl Send for ErrorRouter
impl Sync for ErrorRouter
impl Unpin for ErrorRouter
impl !UnwindSafe for ErrorRouter
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