This commit is contained in:
Timon_Post 2019-05-04 13:46:36 +02:00
parent ee406d47fa
commit 81a0c85f6e

View File

@ -44,25 +44,24 @@ pub fn pos_raw() -> io::Result<(u16, u16)> {
} }
// Read rows and cols through a ad-hoc integer parsing function // Read rows and cols through a ad-hoc integer parsing function
let read_num: fn() -> Result<(i32, char) -> Result<(i32, char), Error> = let read_num: fn() -> Result<(i32, char), Error> = || -> Result<(i32, char), Error> {
|| -> Result<(i32, char), Error> { let mut num = 0;
let mut num = 0; let mut c: char;
let mut c: char;
loop { loop {
let mut buf = [0u8; 1]; let mut buf = [0u8; 1];
io::stdin().read_exact(&mut buf)?; io::stdin().read_exact(&mut buf)?;
c = buf[0] as char; c = buf[0] as char;
if let Some(d) = c.to_digit(10) { if let Some(d) = c.to_digit(10) {
num = if num == 0 { 0 } else { num * 10 }; num = if num == 0 { 0 } else { num * 10 };
num += d as i32; num += d as i32;
} else { } else {
break; break;
}
} }
}
Ok((num, c)) Ok((num, c))
}; };
// Read rows and expect `;` // Read rows and expect `;`
let (rows, c) = read_num()?; let (rows, c) = read_num()?;