Can destructuring be requested when declaring a function?

I'm a bit uncertain about what is going on in the following function declaration:

pub async fn go(Extension(client): Extension<BasicClient>) -> impl IntoResponse { .. }

With Extension(client): Is that destructing an anonymous first parameter (unwrapping it), and naming the unwrapped value client?

I looked in the Book for all the ways destructing can take place, I did not see it in the function declaration so I want to make sure I'm not missing anything here.

Thanks in advance.

- E

That's right.

fn go(Extension(client): Extension<BasicClient>) {

is essentially the same as

fn go(__arg1: Extension<BasicClient>) {
    let Extension(client) = __arg1;

This usage is noted in the book in section 18.1 "All the Places Patterns Can Be Used". In your example signature, Extension(client) is a pattern that introduces a binding, client.


Thank you for the correction. I see now that I was looking at the RFC book that described the destructuring proposal.

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.