From 4e774437b38431d5d7c1ca15d7bee8d50eaf838a Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 8 Oct 2018 22:39:18 +0000 Subject: [PATCH] Simplified some Rust code. --- rust/examples/qrcodegen-worker.rs | 5 +---- rust/src/lib.rs | 6 ++---- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/rust/examples/qrcodegen-worker.rs b/rust/examples/qrcodegen-worker.rs index 5537f19..f35ec80 100644 --- a/rust/examples/qrcodegen-worker.rs +++ b/rust/examples/qrcodegen-worker.rs @@ -102,10 +102,7 @@ fn read_int() -> i16 { let mut chrs: Vec = line.chars().collect(); assert_eq!(chrs.pop().unwrap(), '\n'); let line: String = chrs.iter().cloned().collect(); - match line.parse::() { - Ok(x) => x, - Err(_) => panic!("Invalid number"), - } + line.parse::().expect("Invalid number") } diff --git a/rust/src/lib.rs b/rust/src/lib.rs index e17e8b0..00e6aaf 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -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 {