News for hackers. Stuff that matters.
Re:Thread-per-core by hjl22 on Friday October 06, 2023 @12:03PM (#37792539)
I haven't touched async Rust, but have used normal Rust a little bit.

My understanding is that 'static is program lifetime, meaning either static compile-time data like constant strings, or it is memory leaks. How does this apply to async in practice? Do you need to leak things that you want to make async?

Re:Thread-per-core by pitaj on Friday October 06, 2023 @12:15PM (#37792697)
Most heap-allocated values like `String` are also static. Essentially it means that anything the value references is not on the stack.
Re:Thread-per-core by hjl22 on Saturday October 07, 2023 @01:45PM (#37803836)
Thanks for the explanation. I understand it now.
Re:Thread-per-core by scottlamb on Friday October 06, 2023 @12:12PM (#37792658)
It means spawned futures can't contain references that aren't 'static. But they can own memory. String for example is 'static. Likewise Vec<T>, Box<T>, Arc<T>, Rc<T>, etc. where T: 'static.
Re:Thread-per-core by hjl22 on Saturday October 07, 2023 @01:45PM (#37803838)
Thanks for the explanation. I understand it now.
Re:Thread-per-core by Georgelemental on Friday October 06, 2023 @01:18PM (#37793430)
`T: 'static` means that values of the type `T` own all their data (more specifically, their lifetime is not constrained by the lifetime of anything they reference).

`&'static T` is a reference to something that lives as long as the program (static data or leaked memory).

Re:Thread-per-core by hjl22 on Saturday October 07, 2023 @01:45PM (#37803837)
Thanks for the explanation. I understand it now.
Re:Thread-per-core by pornel on Friday October 06, 2023 @01:27PM (#37793539)
No, when used as a bound, it doesn't really say how long data has to live. It just forbids use of all temporary references (types that are borrowing from something short-lived they don't own).

Lifetime requirements simply don't apply at all to types that own their data. Or another way to see it is that self-contained types like Vec and String automatically meet every lifetime requirement, regardless of how long or short they actually live.

Rust kinda screwed up with terminology here, because the general computing term of "object lifetime" applies to more things than the specific 'lifetime concept that Rust applies to references/loans.

Re:Thread-per-core by hjl22 on Saturday October 07, 2023 @01:45PM (#37803835)
Thanks for the explanation. I understand it now.