pretty new to rust and trying to write a simple web server using Axum. I encountered the following error during compilation:
error: higher-ranked lifetime error
|
16 | .route("/login", post(login));
| ^^^^^^^^^^^
|
= note: could not prove `for<'a> fn(Json<Credentials<'a>>) -> impl Future<Output = Json<Value>> {login}: Handler<(axum_core::extract::private::ViaRequest, Json<Credentials<'a>>), ()>`
I'm not sure what does it mean? Would anyone be able to help on this?
This can be resolved if the struct does not use references. But am trying to not copy the values
Below is the snippet of the code.
use axum::{
routing::post,
Json, Router,
};
use serde::{Deserialize};
use serde_json::{json, Value};
pub async fn get_routers() -> Router {
// Build our application by creating our router.
let routers = Router::new()
.route("/login", post(login));
routers
}
async fn login(Json(credentials): Json<Credentials<'_>>) -> Json<Value> {
let username = credentials.username;
let password = credentials.password;
// some other codes here
Json(json!({ "test": "test", "test1": "test1" }))
}
#[derive(Deserialize, Debug, Clone)]
struct Credentials<'r> {
username: &'r str,
password: &'r str,
}