Skip to content

Commit a6288e7

Browse files
authored
Merge pull request #1274 from illiteratewriter/reference-to-lifetime-in-structs
Add reference to lifetime in structs
2 parents 1d6138a + cbea4cc commit a6288e7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/custom_types/structs.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ There are three types of structures ("structs") that can be created using the
1010
```rust,editable
1111
#[derive(Debug)]
1212
struct Person<'a> {
13+
// The 'a defines a lifetime
1314
name: &'a str,
1415
age: u8,
1516
}
@@ -54,7 +55,7 @@ fn main() {
5455
// Make a new point by using struct update syntax to use the fields of our
5556
// other one
5657
let bottom_right = Point { x: 5.2, ..point };
57-
58+
5859
// `bottom_right.y` will be the same as `point.y` because we used that field
5960
// from `point`
6061
println!("second point: ({}, {})", bottom_right.x, bottom_right.y);
@@ -86,14 +87,15 @@ fn main() {
8687

8788
### Activity
8889

89-
1. Add a function `rect_area` which calculates the area of a rectangle (try
90-
using nested destructuring).
90+
1. Add a function `rect_area` which calculates the area of a rectangle (try
91+
using nested destructuring).
9192
2. Add a function `square` which takes a `Point` and a `f32` as arguments, and returns a `Rectangle` with its lower left corner on the point, and a width and height corresponding to the `f32`.
9293

9394
### See also:
9495

95-
[`attributes`][attributes] and [destructuring][destructuring]
96+
[`attributes`][attributes], [lifetime][lifetime] and [destructuring][destructuring]
9697

9798
[attributes]: ../attribute.md
9899
[c_struct]: https://en.wikipedia.org/wiki/Struct_(C_programming_language)
99100
[destructuring]: ../flow_control/match/destructuring.md
101+
[lifetime]: ../scope/lifetime.md

0 commit comments

Comments
 (0)