My very first rust question. Searched large and far but haven't found the answer yet.
pub fn open(&mut self, row: usize, col: usize) {
let n = self.n; // first question, I had to use this, I couldn't just use self.n as matching expression...
// ... a bit more stuff here
match row {
1 => {
do_up = false;
self.union(self.cell(row, col), 0)
}
n => {
println!("this");
do_down = false;
self.union(self.cell(row, col), self.n)
}
_ => {}
}
}
In my app, row can have different values from 1 to n. The result I am getting is that all other rows than 1 enter the n option.
What I want is that the option 1 code only runs when row is indeed 1, and the n option only when it's indeed n (e.g. if n is 5, then only match row == 5), and all the other values for row just get skipped.
Also, bonus question, if I put self.n directly as an option, then rustc complains. I had to introduce let n = self.n for it to compile. My intuition tells me that the actual reason why it's not working as intended is related to just that...