3 ms·
OK, I see what the problem is. This is the type signature for the body method: fn body<B: Into<Body<'a>>>(self, body: B) -> RequestBuilder<'a> The RequestBuil
by openasocket 10y ago
OK, I see what the problem is. This is the type signature for the body method:
fn body<B: Into<Body<'a>>>(self, body: B) -> RequestBuilder<'a>
The RequestBuilder struct tries to be clever: it just keeps a pointer to what you want the body to be rather than taking ownership of it or copying it. So when you say that "req = req.body(&s)" you've given the request a pointer to your string, but that string is freed inside that if-block. I don't see an obvious fix right now, but I'll update this is I see something.
- fizzbatter 10y agoYea, that's another thing about rust. At times, things like what Hyper's Body method is doing can be quite puzzling. And while Rust's attempt to help is noble, it can end up even more confusing. At times it is awesome, but it can be a lot of visual noise for beginners. Fwiw, https://news.ycombinator.com/item?id=11780196 https://news.ycombinator.com/item?id=11780196 has the answer to my example problem. I'm also inquiring about using lifetimes to solve the problem.