Re:Rust in 2018: easier to use
by littlestymaar on Sunday January 14, 2018 @07:41AM
(#16144025)
You summarized it so well ! It was also a huge source of confusion for me in the beginning.
Would you mind if I made a pull request to the Rust book adding your explaination to the lifetime chapter ?
Re:Rust in 2018: easier to use
by steveklabnik on Sunday January 14, 2018 @02:54PM
(#16145980)
While it doesn't have this literal text, it already does have the equivalent: https://doc.rust-lang.org/book/second-edition/ch10-03-lifeti...
> Lifetime annotations don’t change how long any of the references involved live. In the same way that functions can accept any type when the signature specifies a generic type parameter, functions can accept references with any lifetime when the signature specifies a generic lifetime parameter. What lifetime annotations do is relate the lifetimes of multiple references to each other.
Re:Rust in 2018: easier to use
by littlestymaar on Monday January 15, 2018 @03:48AM
(#16149361)
Cool. I haven't read the second version of the book, and I read the first version about two years ago I think. Glad to see this difficulty is now covered. Carry on with the great job Steve :)
Re:Rust in 2018: easier to use
by steveklabnik on Monday January 15, 2018 @08:26AM
(#16150309)
Ah ha! Yeah, it's quite different.
Thanks :)
Re:Rust in 2018: easier to use
by red75prime on Sunday January 14, 2018 @08:05AM
(#16144094)
I wouldn't. Feel free to use it. But I have the impression that the Rust book contains something to that effect.
"Descriptive and not prescriptive" part probably comes from stackoverflow. I don't remember exactly.
Re:Rust in 2018: easier to use
by steveklabnik on Sunday January 14, 2018 @02:53PM
(#16145977)
I'm not sure where I heard it, but I certainly repeat it. It's not literally in the book though, I'll also reply to your parent about this.
For example, local variables of a function get destroyed on function exit no matter what and you can't prevent it by adding lifetime annotation to a local variable reference you are trying to return.
That was a stumbling block for me.