@@ -485,7 +485,7 @@ For example, we could write a subroutine like this:
485485
486486~~~
487487struct Point {x: float, y: float}
488- fn get_x(p: &'r Point) -> &'r float { &p.x }
488+ fn get_x<'r> (p: &'r Point) -> &'r float { &p.x }
489489~~~
490490
491491Here, the function ` get_x() ` returns a pointer into the structure it
@@ -571,8 +571,8 @@ function:
571571# Rectangle(Point, Size) // upper-left, dimensions
572572# }
573573# fn compute_area(shape: &Shape) -> float { 0f }
574- fn select<T>(shape: &'r Shape, threshold: float,
575- a: &'r T, b: &'r T) -> &'r T {
574+ fn select<'r, T>(shape: &'r Shape, threshold: float,
575+ a: &'r T, b: &'r T) -> &'r T {
576576 if compute_area(shape) > threshold {a} else {b}
577577}
578578~~~
@@ -591,12 +591,12 @@ example:
591591# Rectangle(Point, Size) // upper-left, dimensions
592592# }
593593# fn compute_area(shape: &Shape) -> float { 0f }
594- # fn select<T>(shape: &Shape, threshold: float,
595- # a: &'r T, b: &'r T) -> &'r T {
594+ # fn select<'r, T>(shape: &Shape, threshold: float,
595+ # a: &'r T, b: &'r T) -> &'r T {
596596# if compute_area(shape) > threshold {a} else {b}
597597# }
598598 // -+ r
599- fn select_based_on_unit_circle<T>( // |-+ B
599+ fn select_based_on_unit_circle<'r, T>( // |-+ B
600600 threshold: float, a: &'r T, b: &'r T) -> &'r T { // | |
601601 // | |
602602 let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
@@ -628,8 +628,8 @@ returned. Here is how the new `select()` might look:
628628# Rectangle(Point, Size) // upper-left, dimensions
629629# }
630630# fn compute_area(shape: &Shape) -> float { 0f }
631- fn select<T>(shape: &'tmp Shape, threshold: float,
632- a: &'r T, b: &'r T) -> &'r T {
631+ fn select<'r, 'tmp, T>(shape: &'tmp Shape, threshold: float,
632+ a: &'r T, b: &'r T) -> &'r T {
633633 if compute_area(shape) > threshold {a} else {b}
634634}
635635~~~
@@ -647,8 +647,8 @@ concise to just omit the named lifetime for `shape` altogether:
647647# Rectangle(Point, Size) // upper-left, dimensions
648648# }
649649# fn compute_area(shape: &Shape) -> float { 0f }
650- fn select<T>(shape: &Shape, threshold: float,
651- a: &'r T, b: &'r T) -> &'r T {
650+ fn select<'r, T>(shape: &Shape, threshold: float,
651+ a: &'r T, b: &'r T) -> &'r T {
652652 if compute_area(shape) > threshold {a} else {b}
653653}
654654~~~
0 commit comments