From 326da6808aae6b4e65fd45aa3cb8f94e3425b345 Mon Sep 17 00:00:00 2001 From: Henry Schimke Date: Thu, 4 May 2023 13:53:57 -0500 Subject: [PATCH] clippy fix --- src/common/bit_array.rs | 25 +++++++++---------------- src/common/cpp_essentials/pattern.rs | 27 ++++++++++++++++----------- src/qrcode/cpp_port/data_mask.rs | 1 + 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/common/bit_array.rs b/src/common/bit_array.rs index 058b9e2..79cb0e8 100644 --- a/src/common/bit_array.rs +++ b/src/common/bit_array.rs @@ -410,27 +410,20 @@ impl Default for BitArray { } } -impl Into> for BitArray { - fn into(self) -> Vec { - let mut array = vec![0; self.getSizeInBytes()]; - self.toBytes(0, &mut array, 0, self.getSizeInBytes()); +impl From for Vec { + fn from(value: BitArray) -> Self { + let mut array = vec![0; value.getSizeInBytes()]; + value.toBytes(0, &mut array, 0, value.getSizeInBytes()); array - // let mut arr = vec![0; self.get_size()]; - // for x in 0..self.get_size() { - // if self.get(x) { - // arr[x] = 1; - // } - // } - // arr } } -impl Into> for BitArray { - fn into(self) -> Vec { - let mut array = vec![false; self.size]; +impl From for Vec { + fn from(value: BitArray) -> Self { + let mut array = vec![false; value.size]; - for (pixel, element) in array.iter_mut().enumerate().take(self.size) { - *element = self.get(pixel); + for (pixel, element) in array.iter_mut().enumerate().take(value.size) { + *element = value.get(pixel); } array diff --git a/src/common/cpp_essentials/pattern.rs b/src/common/cpp_essentials/pattern.rs index d299275..d222b2c 100644 --- a/src/common/cpp_essentials/pattern.rs +++ b/src/common/cpp_essentials/pattern.rs @@ -40,6 +40,10 @@ impl PatternRow { self.0.len() } + pub fn is_empty(&self) -> bool { + self.0.is_empty() + } + pub fn into_pattern_view(&self) -> PatternView { PatternView::new(self) } @@ -324,21 +328,21 @@ impl std::ops::Index for PatternView<'_> { } } -impl<'a> Into> for &PatternView<'a> { - fn into(self) -> Vec { - let mut v = vec![PatternType::default(); self.count]; - for i in 0..self.count { - v[i] = self[i]; +impl<'a> From<&PatternView<'a>> for Vec { + fn from(value: &PatternView<'a>) -> Self { + let mut v = vec![PatternType::default(); value.count]; + for i in 0..value.count { + v[i] = value[i]; } v } } -impl<'a, const LEN: usize> Into<[PatternType; LEN]> for &PatternView<'a> { - fn into(self) -> [PatternType; LEN] { +impl<'a, const LEN: usize> From<&PatternView<'a>> for [PatternType; LEN] { + fn from(value: &PatternView<'a>) -> Self { let mut result = [PatternType::default(); LEN]; - for i in 0..self.count { - result[i] = self[i]; + for i in 0..value.count { + result[i] = value[i]; } result } @@ -355,6 +359,7 @@ struct BarAndSpace { space: T, } impl BarAndSpace { + #[allow(dead_code)] pub fn isValid(&self) -> bool { self.bar != T::default() && self.space != T::default() } @@ -420,11 +425,11 @@ impl FixedPattern &[PatternType] { + pub fn as_slice(&self) -> &[PatternType] { &self.data } - fn size(&self) -> usize { + pub fn size(&self) -> usize { N } diff --git a/src/qrcode/cpp_port/data_mask.rs b/src/qrcode/cpp_port/data_mask.rs index ce86906..9ca8675 100644 --- a/src/qrcode/cpp_port/data_mask.rs +++ b/src/qrcode/cpp_port/data_mask.rs @@ -44,6 +44,7 @@ pub fn GetDataMaskBit(maskIndex: u32, x: u32, y: u32, isMicro: Option) -> )) } +#[allow(dead_code)] pub fn GetMaskedBit( bits: &BitMatrix, x: u32,