@@ -485,7 +485,7 @@ For example, we could write a subroutine like this:
485
485
486
486
~~~
487
487
struct 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 }
489
489
~~~
490
490
491
491
Here, the function ` get_x() ` returns a pointer into the structure it
@@ -571,8 +571,8 @@ function:
571
571
# Rectangle(Point, Size) // upper-left, dimensions
572
572
# }
573
573
# 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 {
576
576
if compute_area(shape) > threshold {a} else {b}
577
577
}
578
578
~~~
@@ -591,12 +591,12 @@ example:
591
591
# Rectangle(Point, Size) // upper-left, dimensions
592
592
# }
593
593
# 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 {
596
596
# if compute_area(shape) > threshold {a} else {b}
597
597
# }
598
598
// -+ r
599
- fn select_based_on_unit_circle<T>( // |-+ B
599
+ fn select_based_on_unit_circle<'r, T>( // |-+ B
600
600
threshold: float, a: &'r T, b: &'r T) -> &'r T { // | |
601
601
// | |
602
602
let shape = Circle(Point {x: 0., y: 0.}, 1.); // | |
@@ -628,8 +628,8 @@ returned. Here is how the new `select()` might look:
628
628
# Rectangle(Point, Size) // upper-left, dimensions
629
629
# }
630
630
# 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 {
633
633
if compute_area(shape) > threshold {a} else {b}
634
634
}
635
635
~~~
@@ -647,8 +647,8 @@ concise to just omit the named lifetime for `shape` altogether:
647
647
# Rectangle(Point, Size) // upper-left, dimensions
648
648
# }
649
649
# 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 {
652
652
if compute_area(shape) > threshold {a} else {b}
653
653
}
654
654
~~~
0 commit comments