Compiler warns "variable does not need to be mutable" incorrectly?

I have got actix web api handler function, which receives body argument. The compiler warns that body does not have to be mutable for the api_handler. However, the handler calls a function which requires body to be mutable. Is it incorrect compiler's warning or I am doing something incorrectly?

async fn api_handler(_req: HttpRequest, mut body: web::Payload) -> Result<HttpResponse, Error> {
    let body = utils::receive_body_as_string(body).await?;
    ...
}

pub async fn receive_body_as_string(mut body: actix_web::web::Payload) -> Result<String, actix_web::Error> {
    ...
}

Because the value is owned, you only need to declare it mutable if you're mutating it in that function.

Thanks. This makes sense now

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.