From dfe47102e6b3be17475ed47c8fdd376f9cc88b2d Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Mon, 18 Nov 2024 04:24:45 +0000 Subject: [PATCH] Simplified a bit of code with usize.div_ceil() (Rust 1.73). --- rust/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 92cc3e3..ed89db9 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -985,7 +985,7 @@ impl QrSegment { /// /// Panics if the string contains non-digit characters. pub fn make_numeric(text: &str) -> Self { - let mut bb = BitBuffer(Vec::with_capacity(text.len() * 3 + (text.len() + 2) / 3)); + let mut bb = BitBuffer(Vec::with_capacity(text.len() * 3 + text.len().div_ceil(3))); let mut accumdata: u32 = 0; let mut accumcount: u8 = 0; for b in text.bytes() { @@ -1012,7 +1012,7 @@ impl QrSegment { /// /// Panics if the string contains non-encodable characters. pub fn make_alphanumeric(text: &str) -> Self { - let mut bb = BitBuffer(Vec::with_capacity(text.len() * 5 + (text.len() + 1) / 2)); + let mut bb = BitBuffer(Vec::with_capacity(text.len() * 5 + text.len().div_ceil(2))); let mut accumdata: u32 = 0; let mut accumcount: u32 = 0; for c in text.chars() {