2019-06-19 00:20:50 -04:00
|
|
|
use actix_web::{web, App};
|
2019-06-17 13:46:21 -04:00
|
|
|
// <helpers>
|
2019-06-28 13:31:30 -04:00
|
|
|
use actix_web::{error, Result};
|
2019-06-17 13:46:21 -04:00
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct MyError {
|
|
|
|
name: &'static str,
|
|
|
|
}
|
|
|
|
|
2019-06-28 13:31:30 -04:00
|
|
|
pub fn index() -> Result<&'static str> {
|
2019-06-24 21:18:30 -04:00
|
|
|
let result: Result<&'static str, MyError> = Err(MyError { name: "test error" });
|
2019-06-17 13:46:21 -04:00
|
|
|
|
|
|
|
Ok(result.map_err(|e| error::ErrorBadRequest(e.name))?)
|
|
|
|
}
|
|
|
|
// </helpers>
|
2019-06-24 21:18:30 -04:00
|
|
|
|
2019-06-19 00:20:50 -04:00
|
|
|
pub fn main() {
|
2019-06-24 21:18:30 -04:00
|
|
|
use actix_web::HttpServer;
|
|
|
|
|
|
|
|
HttpServer::new(|| App::new().route("/", web::get().to(index)))
|
|
|
|
.bind("127.0.0.1:8088")
|
|
|
|
.unwrap()
|
|
|
|
.run()
|
|
|
|
.unwrap();
|
2019-06-19 00:20:50 -04:00
|
|
|
}
|