I don't understand how Struct(name) syntax works in function parameters

I just came across a line of code in the first example on this page: State in axum::extract - Rust

async fn handler(
    // access the state via the `State` extractor
    // extracting a state of the wrong type results in a compile error
    State(state): State<AppState>,
) {
    // use `state`...
}

Notice the left hand side of the parameter. I can't find this type of syntax mentioned anywhere in the book. Why and how is this used and where can I read more about it?

It is in the book, of course. The parameter "name" is actually not only a name, it's a pattern.

4 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.