From fe992753d2c7d55a16c1b966961bd27e11e622dd Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Wed, 18 Sep 2019 20:40:23 +0000 Subject: [PATCH] Tweaked Rust code to convert more integer casts from 'as' to 'from'. --- rust/src/lib.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 258761a..be7303c 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -1001,7 +1001,7 @@ impl QrSegment { let mut accumcount: u8 = 0; for &c in text { assert!('0' <= c && c <= '9', "String contains non-numeric characters"); - accumdata = accumdata * 10 + ((c as u32) - ('0' as u32)); + accumdata = accumdata * 10 + (u32::from(c) - u32::from('0')); accumcount += 1; if accumcount == 3 { bb.append_bits(accumdata, 10); @@ -1124,7 +1124,7 @@ impl QrSegment { if seg.numchars >= 1 << ccbits { return None; // The segment's length doesn't fit the field's bit width } - result = result.checked_add(4 + (ccbits as usize) + seg.data.len())?; + result = result.checked_add(4 + usize::from(ccbits) + seg.data.len())?; } Some(result) } @@ -1194,7 +1194,7 @@ impl QrSegmentMode { Byte => [ 8, 16, 16], Kanji => [ 8, 10, 12], Eci => [ 0, 0, 0], - })[((ver.value() + 7) / 17) as usize] + })[usize::from((ver.value() + 7) / 17)] } }