1
0
mirror of https://github.com/actix/actix-website synced 2024-11-27 18:12:57 +01:00
This commit is contained in:
Rob Ede 2023-03-13 17:59:23 +00:00
parent 1a3fedc78f
commit 5fa564fd4e
No known key found for this signature in database
GPG Key ID: 97C636207D3EF933
3 changed files with 6 additions and 6 deletions

View File

@ -1,5 +1,5 @@
// <helpers>
use actix_web::{error, get, App, HttpServer, Result};
use actix_web::{error, get, App, HttpServer};
#[derive(Debug)]
struct MyError {
@ -7,10 +7,10 @@ struct MyError {
}
#[get("/")]
async fn index() -> Result<&'static str> {
let result: Result<&'static str, MyError> = Err(MyError { name: "test error" });
async fn index() -> actix_web::Result<String> {
let result = Err(MyError { name: "test error" });
Ok(result.map_err(|e| error::ErrorBadRequest(e.name))?)
result.map_err(|err| error::ErrorBadRequest(err.name))
}
// </helpers>

View File

@ -3,7 +3,7 @@ use actix_web::{get, App, HttpRequest, HttpServer, Responder};
#[get("/")]
async fn index(req: HttpRequest) -> impl Responder {
let url = req.url_for("youtube", &["oHg5SJYRHA0"]).unwrap();
let url = req.url_for("youtube", ["oHg5SJYRHA0"]).unwrap();
assert_eq!(url.as_str(), "https://youtube.com/watch/oHg5SJYRHA0");
url.to_string()

View File

@ -3,7 +3,7 @@ use actix_web::{get, guard, http::header, HttpRequest, HttpResponse, Result};
#[get("/test/")]
async fn index(req: HttpRequest) -> Result<HttpResponse> {
let url = req.url_for("foo", &["1", "2", "3"])?; // <- generate url for "foo" resource
let url = req.url_for("foo", ["1", "2", "3"])?; // <- generate url for "foo" resource
Ok(HttpResponse::Found()
.insert_header((header::LOCATION, url.as_str()))