Skip to content

Commit

Permalink
Get a hashmap, odd borrowing
Browse files Browse the repository at this point in the history
   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}
  • Loading branch information
nuxeh committed Dec 5, 2021
1 parent b593d4b commit c09d5f5
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions 05/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn main() {
}

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

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

for line in lines {
println!("{:?}", line);
println!("{:?}", line.cast());

line
.cast()
.for_each(|point| {
match points.get(point) {
Some(count) => points.insert(*point, count+1),
None => points.insert(*point, 1),
};
});
//println!("{:?}", line.cast());

for point in line.cast() {
match points.get(&point) {
Some(count) => points.insert(point, count+1),
None => points.insert(point, 1),
};
};
}

println!("{:?}", points);
}

0 comments on commit c09d5f5

Please sign in to comment.