Rust reqwest, get url and text

match clnt.get(link).send().await {
Ok(g) => {
let urler = g.url().as_str();
let ress = g.text().await.unwrap();
},
Err(e) => {}
}

cannot move out of g because it is borrowed
move out of g occurs here

I cant understand what i'am doing wrong help me please

Just look at the signature of Response::url(). It's (&self) -> &Url. This means that the URL is borrowed from self; similarly, the Url::as_str() method borrows the string representation of the Url. Hence, while you have a reference to the URL string, you can't call any other moving or mutating methods on the Response. (Response::text() takes self by value, as it's evident from its signature.)

In general, it's always advisable to start by reading the documentation (including the signature) of the methods you are calling.

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.