Simplified some Rust code.

This commit is contained in:
Project Nayuki 2018-10-08 22:39:18 +00:00
parent 0723ac0d17
commit 4e774437b3
2 changed files with 3 additions and 8 deletions

View File

@ -102,10 +102,7 @@ fn read_int() -> i16 {
let mut chrs: Vec<char> = line.chars().collect();
assert_eq!(chrs.pop().unwrap(), '\n');
let line: String = chrs.iter().cloned().collect();
match line.parse::<i16>() {
Ok(x) => x,
Err(_) => panic!("Invalid number"),
}
line.parse::<i16>().expect("Invalid number")
}

View File

@ -927,10 +927,8 @@ impl QrSegment {
let mut accumdata: u32 = 0;
let mut accumcount: u32 = 0;
for c in text {
let i = match ALPHANUMERIC_CHARSET.iter().position(|x| *x == *c) {
None => panic!("String contains unencodable characters in alphanumeric mode"),
Some(j) => j,
};
let i = ALPHANUMERIC_CHARSET.iter().position(|x| *x == *c)
.expect("String contains unencodable characters in alphanumeric mode");
accumdata = accumdata * 45 + (i as u32);
accumcount += 1;
if accumcount == 2 {