Skip to content

Expand further on <> syntax in TRPL. #27538

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 5, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions src/doc/trpl/lifetimes.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@ Before we get to that, though, let’s break the explicit example down:
fn bar<'a>(...)
```

This part declares our lifetimes. This says that `bar` has one lifetime, `'a`.
If we had two reference parameters, it would look like this:
We previously talked a little about [function syntax][functions], but we didn’t
discuss the `<>`s after a function’s name. A function can have ‘generic
parameters’ between the `<>`s, of which lifetimes are one kind. We’ll discuss
other kinds of generics [later in the book][generics], but for now, let’s
just focus on the lifteimes aspect.

[functions]: functions.html
[generics]: generics.html

We use `<>` to declare our lifetimes. This says that `bar` has one lifetime,
`'a`. If we had two reference parameters, it would look like this:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be a bit deceptive -- a function can have many more lifetimes that aren't declared thanks to elision.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From a technical perspective I each function can have multiple lifetime parameters, but from the perspective of just explaining syntax I think it's fine to assume that "lifetime parameter" is the same as "explicitly declared lifetime parameter". Elision kinda fits into the same system later on, so I don't think that we're going to confuse anyone from this.



```rust,ignore
fn bar<'a, 'b>(...)
Expand Down