mirror of
https://github.com/actix/examples
synced 2025-06-26 09:17:41 +02:00
Use captured args in format string (#558)
This commit is contained in:
@ -22,12 +22,12 @@ async fn favicon() -> Result<impl Responder> {
|
||||
/// simple index handler
|
||||
#[get("/welcome")]
|
||||
async fn welcome(req: HttpRequest, session: Session) -> Result<HttpResponse> {
|
||||
println!("{:?}", req);
|
||||
println!("{req:?}");
|
||||
|
||||
// session
|
||||
let mut counter = 1;
|
||||
if let Some(count) = session.get::<i32>("counter")? {
|
||||
println!("SESSION value: {}", count);
|
||||
println!("SESSION value: {count}");
|
||||
counter = count + 1;
|
||||
}
|
||||
|
||||
@ -63,7 +63,7 @@ async fn response_body(path: web::Path<String>) -> HttpResponse {
|
||||
|
||||
/// handler with path parameters like `/user/{name}/`
|
||||
async fn with_param(req: HttpRequest, path: web::Path<(String,)>) -> HttpResponse {
|
||||
println!("{:?}", req);
|
||||
println!("{req:?}");
|
||||
|
||||
HttpResponse::Ok()
|
||||
.content_type(ContentType::plaintext())
|
||||
@ -110,7 +110,7 @@ async fn main() -> io::Result<()> {
|
||||
// redirect
|
||||
.service(
|
||||
web::resource("/").route(web::get().to(|req: HttpRequest| async move {
|
||||
println!("{:?}", req);
|
||||
println!("{req:?}");
|
||||
HttpResponse::Found()
|
||||
.insert_header((header::LOCATION, "static/welcome.html"))
|
||||
.finish()
|
||||
|
@ -1,7 +1,7 @@
|
||||
use actix_web::{middleware, web, App, HttpRequest, HttpServer};
|
||||
|
||||
async fn index(req: HttpRequest) -> &'static str {
|
||||
println!("REQ: {:?}", req);
|
||||
println!("REQ: {req:?}");
|
||||
"Hello world!"
|
||||
}
|
||||
|
||||
|
@ -36,7 +36,7 @@ async fn index(
|
||||
counter_atomic: Data<AtomicUsize>,
|
||||
req: HttpRequest,
|
||||
) -> HttpResponse {
|
||||
println!("{:?}", req);
|
||||
println!("{req:?}");
|
||||
|
||||
// Increment the counters
|
||||
*counter_mutex.lock().unwrap() += 1;
|
||||
|
@ -80,7 +80,7 @@ pub async fn update(
|
||||
"put" => toggle(db, params).await,
|
||||
"delete" => delete(db, params, session).await,
|
||||
unsupported_method => {
|
||||
let msg = format!("Unsupported HTTP method: {}", unsupported_method);
|
||||
let msg = format!("Unsupported HTTP method: {unsupported_method}");
|
||||
Err(error::ErrorBadRequest(msg))
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user