From 621a77757eecfbcc77ac87c0af496b6e8d366c7f Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sat, 10 Aug 2019 02:41:40 +0000 Subject: [PATCH] Simplified miscellaneous Rust code, due to clippy linting. --- rust/examples/qrcodegen-worker.rs | 9 ++++----- rust/src/lib.rs | 10 +++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/rust/examples/qrcodegen-worker.rs b/rust/examples/qrcodegen-worker.rs index a6c3ca3..6726d9b 100644 --- a/rust/examples/qrcodegen-worker.rs +++ b/rust/examples/qrcodegen-worker.rs @@ -66,13 +66,12 @@ fn main() { assert!(boostecl >> 1 == 0); // Make segments for encoding - let segs: Vec; - if isascii { + let segs: Vec = if isascii { let chrs: Vec = std::str::from_utf8(&data).unwrap().chars().collect(); - segs = QrSegment::make_segments(&chrs); + QrSegment::make_segments(&chrs) } else { - segs = vec![QrSegment::make_bytes(&data)]; - } + vec![QrSegment::make_bytes(&data)] + }; // Try to make QR Code symbol let msk = if mask == -1 { None } else { Some(Mask::new(mask as u8)) }; diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 7cfd653..67afbb9 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -834,8 +834,8 @@ impl QrCode { let n = runhistory[1]; assert!(n <= self.size * 3); let core = n > 0 && runhistory[2] == n && runhistory[3] == n * 3 && runhistory[4] == n && runhistory[5] == n; - return if core && runhistory[0] >= n * 4 && runhistory[6] >= n { 1 } else { 0 } - + if core && runhistory[6] >= n * 4 && runhistory[0] >= n { 1 } else { 0 }; + ( i32::from(core && runhistory[0] >= n * 4 && runhistory[6] >= n) + + i32::from(core && runhistory[6] >= n * 4 && runhistory[0] >= n)) } @@ -1088,11 +1088,7 @@ impl QrSegment { /// The character count (numchars) must agree with the mode and /// the bit buffer length, but the constraint isn't checked. pub fn new(mode: QrSegmentMode, numchars: usize, data: Vec) -> Self { - Self { - mode: mode, - numchars: numchars, - data: data, - } + Self { mode, numchars, data } }