Add an elided bound example in unbounded lifetimes section to make stuff clearer
Nobody has claimed this yet.
- Dominant language
- CSS
- Stars
- 2.3k
- Forks
- 325
- PR merge metrics
- No merged PRs in 30d
Description
In the book written, quoting:
any output lifetimes that don't derive from inputs are unbounded
which refers to the following function of what not to do.
My suggestion is to add after the following quote:
The easiest way to avoid unbounded lifetimes is to use lifetime elision at the function boundary.
A "correct" code example to make stuff clearer, something like:
// lifetime 'a in input and output are elided. Bounded.
fn get_str(s: &str) -> &str {
&s
}
fn main() {
let soon_dropped = String::from("hello");
let not_dangling = get_str(&soon_dropped);
drop(soon_dropped);
println!("Invalid str: {}", not_dangling); // Invalid str: gӚ_`
}
If this seems logical enough for you, I'd be more then happy to create a PR.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Read src/unbounded-lifetimes.md at the linked unbounded lifetimes section, especially the guidance on lifetime elision at function boundaries. Add a clear bounded-lifetime example after that passage, and verify that the documented Rust example accurately demonstrates the intended lifetime behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100