4 ms·
I try to idle in there during NYC 9-5ish at least, but depending on your time zone, it can be tough. Without compiling myself, it can be a bit tricky, but...
by steveklabnik 10y ago
I try to idle in there during NYC 9-5ish at least, but depending on your time zone, it can be tough.
Without compiling myself, it can be a bit tricky, but...
Yes, so the issue here is, your String will go out of scope at the end if the if let, on 14. But you're trying to store a reference to it in something that lives longer: the req will continue to live afterwards. So yes, you need to move s outside of the block somehow; there are a few different ways of doing this. What I'd try first is something like this: https://gist.github.com/steveklabnik/54cf7a4a522cd1a7c6e0130760903b75 https://gist.github.com/steveklabnik/54cf7a4a522cd1a7c6e0130...
Now that the binding lives in the outer scope, it will live longer than the `if let`, you're basically moving it out. I'm trusting the compiler's control flow analysis here; it should let you do this, given that you only use s after you've assigned to it.
- fizzbatter 10y agoIndeed, that worked! So, it's good to know i had the right idea (moving the data out of the block), but i didn't think to store it above the request body. I was trying to be clever, and use explicitly say that `s` should live for the lifetime of the parent function. Any idea if that is possible in this case? edit: Sidenote, i appreciate that you hang in Rust Beginners, i didn't mean to imply that people weren't being helpful. Just that, it can be difficult to find a solution at times. On the plus side, i managed to help (i hope haha) a guy in #rust-beginners today, so hopefully i've paid it forward a bit. Appreciate your help!
- steveklabnik 10y agoYeah no worries :) > Any idea if that is possible in this case? This is what I meant by liftimes being descriptive, not prescriptive: you can't add an annotation and make something live longer. Moving the binding itself is the only way.