|
5 | 5 | use rocket::{Rocket, Build};
|
6 | 6 | use rocket::response::{content, status};
|
7 | 7 | use rocket::http::{Status, uri::Origin};
|
8 |
| - |
9 |
| -// Custom impl so I can implement Static (or Transient) --- |
10 |
| -// We should upstream implementations for most common error types |
11 |
| -// in transient itself |
12 |
| -use rocket::catcher::{Static}; |
13 | 8 | use std::num::ParseIntError;
|
14 | 9 |
|
15 |
| -#[derive(Debug)] |
16 |
| -#[allow(unused)] |
17 |
| -struct IntErr(ParseIntError); |
18 |
| -impl Static for IntErr {} |
19 |
| - |
20 |
| -struct I8(i8); |
21 |
| -use rocket::request::FromParam; |
22 |
| -impl FromParam<'_> for I8 { |
23 |
| - type Error = IntErr; |
24 |
| - fn from_param(param: &str) -> Result<Self, Self::Error> { |
25 |
| - param.parse::<i8>().map(Self).map_err(IntErr) |
26 |
| - } |
27 |
| -} |
28 |
| -// ------------------------------ |
29 |
| - |
30 | 10 | #[get("/hello/<name>/<age>")]
|
31 |
| -fn hello(name: &str, age: I8) -> String { |
32 |
| - format!("Hello, {} year old named {}!", age.0, name) |
| 11 | +fn hello(name: &str, age: i8) -> String { |
| 12 | + format!("Hello, {} year old named {}!", age, name) |
33 | 13 | }
|
34 | 14 |
|
35 | 15 | #[get("/<code>")]
|
@@ -60,7 +40,7 @@ fn hello_not_found(uri: &Origin<'_>) -> content::RawHtml<String> {
|
60 | 40 |
|
61 | 41 | // `error` and `status` type. All other params must be `FromOrigin`?
|
62 | 42 | #[catch(422, error = "<e>" /*, status = "<_s>"*/)]
|
63 |
| -fn param_error(e: &IntErr, uri: &Origin<'_>) -> content::RawHtml<String> { |
| 43 | +fn param_error(e: &ParseIntError, uri: &Origin<'_>) -> content::RawHtml<String> { |
64 | 44 | content::RawHtml(format!("\
|
65 | 45 | <p>Sorry, but '{}' is not a valid path!</p>\
|
66 | 46 | <p>Try visiting /hello/<name>/<age> instead.</p>\
|
|
0 commit comments