Skip to content

Commit c09d5f5

Browse files
committedDec 5, 2021
Get a hashmap, odd borrowing
Compiling aoc0521 v0.1.0 (/home/ed/git/aoc-2021/05) warning: cannot borrow `points` as mutable because it is also borrowed as immutable --> src/main.rs:85:32 | 84 | match points.get(&point) { | ------ immutable borrow occurs here 85 | Some(count) => points.insert(point, count+1), | ^^^^^^ ----- immutable borrow later used here | | | mutable borrow occurs here | = note: `#[warn(mutable_borrow_reservation_conflict)]` on by default = warning: this borrowing pattern was not meant to be accepted, and may become a hard error in the future = note: for more information, see issue #59159 <rust-lang/rust#59159> warning: `aoc0521` (bin "aoc0521") generated 1 warning Finished dev [unoptimized + debuginfo] target(s) in 1.19s Running `target/debug/aoc0521` [ Line { start: Point { x: 0, y: 9, }, end: Point { x: 5, y: 9, }, }, Line { start: Point { x: 8, y: 0, }, end: Point { x: 0, y: 8, }, }, Line { start: Point { x: 9, y: 4, }, end: Point { x: 3, y: 4, }, }, Line { start: Point { x: 2, y: 2, }, end: Point { x: 2, y: 1, }, }, Line { start: Point { x: 7, y: 0, }, end: Point { x: 7, y: 4, }, }, Line { start: Point { x: 6, y: 4, }, end: Point { x: 2, y: 0, }, }, Line { start: Point { x: 0, y: 9, }, end: Point { x: 2, y: 9, }, }, Line { start: Point { x: 3, y: 4, }, end: Point { x: 1, y: 4, }, }, Line { start: Point { x: 0, y: 0, }, end: Point { x: 8, y: 8, }, }, Line { start: Point { x: 5, y: 5, }, end: Point { x: 8, y: 2, }, }, ] Line { start: Point { x: 0, y: 9 }, end: Point { x: 5, y: 9 } } dx=5 dy=0 n=5 ix=1 iy=0 Line { start: Point { x: 8, y: 0 }, end: Point { x: 0, y: 8 } } dx=-8 dy=8 n=8 ix=1 iy=-1 Line { start: Point { x: 9, y: 4 }, end: Point { x: 3, y: 4 } } dx=-6 dy=0 n=6 ix=1 iy=0 Line { start: Point { x: 2, y: 2 }, end: Point { x: 2, y: 1 } } dx=0 dy=-1 n=1 ix=0 iy=1 Line { start: Point { x: 7, y: 0 }, end: Point { x: 7, y: 4 } } dx=0 dy=4 n=4 ix=0 iy=1 Line { start: Point { x: 6, y: 4 }, end: Point { x: 2, y: 0 } } dx=-4 dy=-4 n=4 ix=1 iy=1 Line { start: Point { x: 0, y: 9 }, end: Point { x: 2, y: 9 } } dx=2 dy=0 n=2 ix=1 iy=0 Line { start: Point { x: 3, y: 4 }, end: Point { x: 1, y: 4 } } dx=-2 dy=0 n=2 ix=1 iy=0 Line { start: Point { x: 0, y: 0 }, end: Point { x: 8, y: 8 } } dx=8 dy=8 n=8 ix=1 iy=1 Line { start: Point { x: 5, y: 5 }, end: Point { x: 8, y: 2 } } dx=3 dy=-3 n=3 ix=1 iy=-1 {Point { x: 8, y: 0 }: 1, Point { x: 8, y: 8 }: 1, Point { x: 6, y: 6 }: 1, Point { x: 10, y: 4 }: 1, Point { x: 7, y: 2 }: 1, Point { x: 2, y: 3 }: 1, Point { x: 4, y: 4 }: 2, Point { x: 11, y: 4 }: 1, Point { x: 7, y: 0 }: 1, Point { x: 7, y: 5 }: 1, Point { x: 12, y: -4 }: 1, Point { x: 3, y: 4 }: 1, Point { x: 7, y: 7 }: 1, Point { x: 10, y: -2 }: 1, Point { x: 1, y: 1 }: 1, Point { x: 8, y: 2 }: 1, Point { x: 11, y: -3 }: 1, Point { x: 2, y: 2 }: 2, Point { x: 7, y: 1 }: 1, Point { x: 7, y: 3 }: 2, Point { x: 6, y: 4 }: 2, Point { x: 9, y: 7 }: 1, Point { x: 13, y: 4 }: 1, Point { x: 3, y: 3 }: 1, Point { x: 15, y: -7 }: 1, Point { x: 2, y: 9 }: 2, Point { x: 10, y: 8 }: 1, Point { x: 3, y: 9 }: 1, Point { x: 9, y: -1 }: 1, Point { x: 13, y: -5 }: 1, Point { x: 5, y: 9 }: 1, Point { x: 5, y: 4 }: 1, Point { x: 4, y: 9 }: 1, Point { x: 16, y: -8 }: 1, Point { x: 9, y: 4 }: 1, Point { x: 12, y: 4 }: 1, Point { x: 0, y: 9 }: 2, Point { x: 14, y: -6 }: 1, Point { x: 15, y: 4 }: 1, Point { x: 8, y: 6 }: 1, Point { x: 5, y: 5 }: 2, Point { x: 7, y: 4 }: 1, Point { x: 1, y: 9 }: 2, Point { x: 14, y: 4 }: 1, Point { x: 0, y: 0 }: 1}
1 parent b593d4b commit c09d5f5

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed
 

Diff for: ‎05/src/main.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ fn main() {
6767
}
6868

6969
fn run(i: &str) {
70-
let points: HashMap<Point, usize> = HashMap::new();
70+
let mut points: HashMap<Point, usize> = HashMap::new();
7171

7272
let lines: Vec<Line> = i
7373
.lines()
@@ -78,15 +78,15 @@ fn run(i: &str) {
7878

7979
for line in lines {
8080
println!("{:?}", line);
81-
println!("{:?}", line.cast());
82-
83-
line
84-
.cast()
85-
.for_each(|point| {
86-
match points.get(point) {
87-
Some(count) => points.insert(*point, count+1),
88-
None => points.insert(*point, 1),
89-
};
90-
});
81+
//println!("{:?}", line.cast());
82+
83+
for point in line.cast() {
84+
match points.get(&point) {
85+
Some(count) => points.insert(point, count+1),
86+
None => points.insert(point, 1),
87+
};
88+
};
9189
}
90+
91+
println!("{:?}", points);
9292
}

0 commit comments

Comments
 (0)