Make Bob reply with a static lifetime#535
Make Bob reply with a static lifetime#535ccouzens wants to merge 1 commit intoexercism:masterfrom ccouzens:static_bob
Conversation
When implementing Bob, it would be very unusual for his reply to have anyting but a static lifetime
|
While that's true, what benefit is there in requiring a static lifetime here? |
|
@coriolinus to familiarise Rust learners to the static lifetime syntax and the situations it might be used. But I agree, it's not a large improvement. I think the 2nd lifetime-elision rule made the signature fn reply<'a>(message: &'a str) -> &'a strwhich will prevent Rust from dropping the message memory until the reply is dropped. It's not going to make much difference within the test suite, but I think it's the correct thing to do. |
|
I agree with you about what the unelided computed lifetimes are. If the point is to decouple the two lifetimes, there are a few options:
In my interpretation, the point of the bob exercise is to demonstrate that functions can in fact return an However, the penalty associated with option 2 isn't trivial either: we want to encourage people to think in terms of APIs which are minimally restrictive, and I'm inclined against merging this on the grounds that it imposes an (admittedly rarely encountered) implementation restriction on the students in service of an unnoticeable performance improvement. I am willing to be overridden on this if other maintainers feel strongly. If no further discussion occurs, I will close without merging not sooner than Friday, 25 May. |
Fair enough. I'm happy for it to be closed unless someone else pushes for it. |
|
I remmeber that when we added When we considered whether to add I do see how adding I can't currently see myself supporting adding it here, given my current understanding of the relative advantages and disadvantages For my curiosity, can I ask someone to show me an implementation that has |
When implementing Bob, it would be very unusual for his reply to have
anyting but a static lifetime