2019-06-19 06:20:50 +02:00
|
|
|
pub mod helpers;
|
2019-06-28 20:50:15 +02:00
|
|
|
pub mod logging;
|
2019-06-19 06:20:50 +02:00
|
|
|
pub mod override_error;
|
|
|
|
pub mod recommend_one;
|
2019-06-25 03:18:30 +02:00
|
|
|
pub mod recommend_two;
|
|
|
|
|
2019-06-17 19:46:21 +02:00
|
|
|
// <response-error>
|
2019-06-28 20:22:51 +02:00
|
|
|
use actix_web::{error, Result};
|
2020-09-12 17:21:54 +02:00
|
|
|
use derive_more::{Display, Error};
|
2019-06-17 19:46:21 +02:00
|
|
|
|
2020-09-12 17:21:54 +02:00
|
|
|
#[derive(Debug, Display, Error)]
|
|
|
|
#[display(fmt = "my error: {}", name)]
|
2019-12-28 16:26:17 +01:00
|
|
|
struct MyError {
|
2019-06-17 19:46:21 +02:00
|
|
|
name: &'static str,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Use default implementation for `error_response()` method
|
|
|
|
impl error::ResponseError for MyError {}
|
|
|
|
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn index() -> Result<&'static str, MyError> {
|
2019-06-17 19:46:21 +02:00
|
|
|
Err(MyError { name: "test" })
|
|
|
|
}
|
|
|
|
// </response-error>
|
2019-06-25 03:18:30 +02:00
|
|
|
|
2020-09-12 17:21:54 +02:00
|
|
|
#[actix_web::main]
|
2019-12-28 16:26:17 +01:00
|
|
|
async fn main() -> std::io::Result<()> {
|
2019-06-27 01:18:43 +02:00
|
|
|
use actix_web::{web, App, HttpServer};
|
2019-06-25 03:18:30 +02:00
|
|
|
|
2019-06-27 01:18:43 +02:00
|
|
|
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
2022-02-26 04:56:24 +01:00
|
|
|
.bind(("127.0.0.1", 8080))?
|
2019-06-27 01:18:43 +02:00
|
|
|
.run()
|
2019-12-28 16:26:17 +01:00
|
|
|
.await
|
2019-06-19 06:20:50 +02:00
|
|
|
}
|