Whatr are "extractors" as I can read in axum documentation?

Hi !

I'm reading axum documentation (never used it). I can see this:

async fn create_user(Json(payload): Json<CreateUser>) {
    // ...
}

(full documentation)

Which rust feature is used to declare this Json(payload) function parameter ? For now, I only know function parameters as a variable name ...

Thanks !

That's just a pattern. Json is defined as

pub struct Json<T>(pub T);

so you can use the Json(x) to assign x to the value inside of Json.

2 Likes

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.