1
0
mirror of https://github.com/google/comprehensive-rust.git synced 2024-11-21 13:25:53 +02:00

Simplify with local variable (#2423)

This reduces the vertical space needed.
This commit is contained in:
Martin Geisler 2024-10-16 11:28:30 +02:00 committed by GitHub
parent dcdf3915ec
commit 4c78c3be6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -15,8 +15,6 @@ This is not inference -- it is just a syntactic shorthand.
- If there are multiple argument lifetimes, but the first one is for `self`,
that lifetime is given to all un-annotated return values.
<!-- mdbook-xgettext: skip -->
```rust,editable
#[derive(Debug)]
struct Point(i32, i32);
@ -41,13 +39,8 @@ fn nearest<'a>(points: &'a [Point], query: &Point) -> Option<&'a Point> {
}
fn main() {
println!(
"{:?}",
nearest(
&[Point(1, 0), Point(1, 0), Point(-1, 0), Point(0, -1),],
&Point(0, 2)
)
);
let points = &[Point(1, 0), Point(1, 0), Point(-1, 0), Point(0, -1)];
println!("{:?}", nearest(points, &Point(0, 2)));
}
```