Re:Programming in Rust: the good, the bad, the ugly
by andrenth on Tuesday March 12, 2019 @09:00PM
(#19374725)
I wish there was a way to escape lifetime annotation propagation in Rust. What I mean is, if you have a struct with an owned field that you refactor to a borrow, you have to add <‘a> everywhere that struct name appears in your program.
[ Parent
| on HN ]
Re:Programming in Rust: the good, the bad, the ugly
by beatgammit on Tuesday March 12, 2019 @10:52PM
(#19375253)
I'm hopeful that the work on non-lexical lifetimes will extend to this in some fashion, but honestly I'm not sure it's possible while making the same guarantees since you need to make sure that the borrow expires before the data becomes invalid.
However, in many cases, you probably just want a Box or something instead of a borrow within a struct. Do you have a specific example where you want a borrow?
Re:Programming in Rust: the good, the bad, the ugly
by steveklabnik on Wednesday March 13, 2019 @12:00AM
(#19375607)
At most, you’d have to propagate a <‘_>; the lifetime is part of the type and showing it matters for the same reason showing any other type parameter matters.
Re:Programming in Rust: the good, the bad, the ugly
by andrenth on Tuesday March 12, 2019 @11:53PM
(#19375573)
Well let’s say you read command line args into a Vec<String> and then you want to use each in some Foo struct, but you want to avoid clones, so you make the field a &str. Now your Foo must become Foo<‘a> everywhere.
I understand the guarantees, it’s just the syntactic overhead that annoys me.