cargo clippy --fix

This commit is contained in:
Henry Schimke
2023-05-04 13:45:57 -05:00
parent e8501c1b6e
commit 634722a806
16 changed files with 50 additions and 50 deletions

View File

@@ -334,6 +334,7 @@ fn testVCardTypes() {
);
}
#[allow(clippy::too_many_arguments)]
fn doTest(
contents: &str,
title: &str,

View File

@@ -197,6 +197,7 @@ fn doTestShort(
);
}
#[allow(clippy::too_many_arguments)]
fn doTest(
contents: &str,
description: &str,

View File

@@ -82,6 +82,7 @@ fn test_vin() {
);
}
#[allow(clippy::too_many_arguments)]
fn do_test(
contents: &str,
wmi: &str,

View File

@@ -429,8 +429,8 @@ impl Into<Vec<bool>> for BitArray {
fn into(self) -> Vec<bool> {
let mut array = vec![false; self.size];
for pixel in 0..self.size {
array[pixel] = self.get(pixel);
for (pixel, element) in array.iter_mut().enumerate().take(self.size) {
*element = self.get(pixel);
}
array

View File

@@ -139,7 +139,7 @@ impl BitSource {
num_bits -= toRead;
bit_offset += toRead;
if bit_offset == 8 {
bit_offset = 0;
//bit_offset = 0;
byte_offset += 1;
}
}

View File

@@ -100,12 +100,12 @@ impl FormatInformation {
// Some QR codes apparently do not apply the XOR mask. Try without and with additional masking.
for mask in [0, mask] {
// for (auto mask : {0, mask})
for bitsIndex in 0..bits.len() {
for (bitsIndex, bit_set) in bits.iter().enumerate() {
// for (int bitsIndex = 0; bitsIndex < Size(bits); ++bitsIndex)
for [pattern, index] in lookup {
// for (const auto& [pattern, index] : lookup) {
// Find the int in lookup with fewest bits differing
let hammingDist = ((bits[bitsIndex] ^ mask) ^ pattern).count_ones();
let hammingDist = ((bit_set ^ mask) ^ pattern).count_ones();
if hammingDist < fi.hammingDistance {
// if (int hammingDist = BitHacks::CountBitsSet((bits[bitsIndex] ^ mask) ^ pattern); hammingDist < fi.hammingDistance) {
fi.index = index as u8;

View File

@@ -63,12 +63,11 @@ impl Version {
pub fn DecodeVersionInformation(versionBitsA: i32, versionBitsB: i32) -> Result<VersionRef> {
let mut bestDifference = u32::MAX;
let mut bestVersion = 0;
let mut i = 0;
for targetVersion in VERSION_DECODE_INFO {
for (i, targetVersion) in VERSION_DECODE_INFO.into_iter().enumerate() {
// for (int targetVersion : VERSION_DECODE_INFO) {
// Do the version info bits match exactly? done.
if targetVersion == versionBitsA as u32 || targetVersion == versionBitsB as u32 {
return Self::getVersionForNumber(i + 7);
return Self::getVersionForNumber(i as u32 + 7);
}
// Otherwise see if this is the closest to a real version info bit string
// we have seen so far
@@ -80,12 +79,11 @@ impl Version {
bestDifference = bitsDifference;
}
}
i += 1;
}
// We can tolerate up to 3 bits of error since no two version info codewords will
// differ in less than 8 bits.
if bestDifference <= 3 {
return Self::getVersionForNumber(bestVersion);
return Self::getVersionForNumber(bestVersion as u32);
}
// If we didn't find a close enough match, fail
Err(Exceptions::ILLEGAL_STATE)

View File

@@ -49,10 +49,10 @@ where
Self::default()
}
pub fn with_eci_string_builder(src: ECIStringBuilder) -> Self {
let mut new_self = Self::default();
new_self.content = src;
new_self
DecoderResult::<T> {
content: src,
..Default::default()
}
}
pub fn isValid(&self) -> bool {

View File

@@ -80,7 +80,7 @@ pub struct PatternViewIterator<'a> {
current_position: usize,
}
impl<'a> Iterator for PatternViewIterator<'_> {
impl Iterator for PatternViewIterator<'_> {
type Item = PatternType;
fn next(&mut self) -> Option<Self::Item> {
@@ -243,7 +243,7 @@ impl<'a> PatternView<'a> {
pub fn shift(&mut self, n: usize) -> bool {
self.current += n;
!self.data.0.is_empty() && self.start + self.count <= (self.start + self.count)
!self.data.0.is_empty() //&& self.start + self.count <= (self.start + self.count)
}
pub fn skipPair(&mut self) -> bool {
@@ -278,7 +278,7 @@ impl<'a> PatternView<'a> {
}
}
impl<'a> std::ops::Index<isize> for PatternView<'_> {
impl std::ops::Index<isize> for PatternView<'_> {
type Output = PatternType;
fn index(&self, index: isize) -> &Self::Output {
@@ -301,7 +301,7 @@ impl<'a> std::ops::Index<isize> for PatternView<'_> {
}
}
impl<'a> std::ops::Index<usize> for PatternView<'_> {
impl std::ops::Index<usize> for PatternView<'_> {
type Output = PatternType;
fn index(&self, index: usize) -> &Self::Output {
@@ -316,7 +316,7 @@ impl<'a> std::ops::Index<usize> for PatternView<'_> {
}
}
impl<'a> std::ops::Index<i32> for PatternView<'_> {
impl std::ops::Index<i32> for PatternView<'_> {
type Output = PatternType;
fn index(&self, index: i32) -> &Self::Output {

View File

@@ -37,7 +37,7 @@ impl GridSampler for DefaultGridSampler {
dimensionY: u32,
controls: &[SamplerControl],
) -> Result<(BitMatrix, [Point; 4])> {
if dimensionX <= 0 || dimensionY <= 0 {
if dimensionX == 0 || dimensionY == 0 {
return Err(Exceptions::NOT_FOUND);
}

View File

@@ -417,9 +417,10 @@ fn test_encode_decode_random(field: GenericGFRef, dataSize: usize, ecSize: usize
for _i in 0..iterations {
//for (int i = 0; i < iterations; i++) {
// generate random data
for k in 0..dataSize {
for data in dataWords.iter_mut().take(dataSize) {
// for k in 0..dataSize {
//for (int k = 0; k < dataSize; k++) {
dataWords[k] = random.gen_range(0..field.getSize().try_into().unwrap());
*data = random.gen_range(0..field.getSize().try_into().unwrap());
}
// generate ECC words
message[0..dataWords.len()].clone_from_slice(&dataWords[..]);

View File

@@ -116,12 +116,12 @@ mod BitArrayBuilderTest {
checkBinary(&pairValues, expected);
}
fn checkBinary(pairValues: &Vec<Vec<u32>>, expected: &str) {
fn checkBinary(pairValues: &[Vec<u32>], expected: &str) {
let binary = buildBitArray(pairValues);
assert_eq!(expected, binary.to_string());
}
fn buildBitArray(pairValues: &Vec<Vec<u32>>) -> BitArray {
fn buildBitArray(pairValues: &[Vec<u32>]) -> BitArray {
let mut pairs = Vec::new(); //new ArrayList<>();
for (i, pair) in pairValues.iter().enumerate() {
// for (int i = 0; i < pairValues.length; ++i) {

View File

@@ -137,8 +137,8 @@ pub fn DecodeByteSegment(
pub fn ToAlphaNumericChar(value: u32) -> Result<char> {
let value = value as usize;
/**
* See ISO 18004:2006, 6.4.4 Table 5
*/
* See ISO 18004:2006, 6.4.4 Table 5
*/
const ALPHANUMERIC_CHARS: [char; 45] = [
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
@@ -301,15 +301,14 @@ pub fn DecodeBitStream(
let res = (|| {
while !IsEndOfStream(&mut bits, version)? {
let mode: Mode;
if modeBitLength == 0 {
mode = Mode::NUMERIC; // MicroQRCode version 1 is always NUMERIC and modeBitLength is 0
let mode: Mode = if modeBitLength == 0 {
Mode::NUMERIC // MicroQRCode version 1 is always NUMERIC and modeBitLength is 0
} else {
mode = Mode::CodecModeForBits(
Mode::CodecModeForBits(
bits.readBits(modeBitLength as usize)?,
Some(version.isMicroQRCode()),
)?;
}
)?
};
match mode {
Mode::FNC1_FIRST_POSITION => {

View File

@@ -99,10 +99,9 @@ pub fn FindFinderPatterns(image: &BitMatrix, tryHarder: bool) -> FinderPatterns
);
// make sure p is not 'inside' an already found pattern area
if res
if !res
.iter()
.find(|old| Point::distance(p, old.p) < (old.size as f32) / 2.0)
.is_none()
.any(|old| Point::distance(p, old.p) < (old.size as f32) / 2.0)
{
// if (FindIf(res, [p](const auto& old) { return distance(p, old) < old.size / 2; }) == res.end()) {
let pattern = LocateConcentricPattern::<E2E, 5, 7>(
@@ -149,8 +148,8 @@ pub fn GenerateFinderPatternSets(patterns: &mut FinderPatterns) -> FinderPattern
* (((b).size as f64) / ((a).size as f64)).powi(2) //std::pow(double(b.size) / a.size, 2)
};
let cosUpper: f64 = (45.0_f64 / 180.0 * 3.1415).cos(); // TODO: use c++20 std::numbers::pi_v
let cosLower: f64 = (135.0_f64 / 180.0 * 3.1415).cos();
let cosUpper: f64 = (45.0_f64 / 180.0 * std::f64::consts::PI).cos(); // TODO: use c++20 std::numbers::pi_v
let cosLower: f64 = (135.0_f64 / 180.0 * std::f64::consts::PI).cos();
let nbPatterns = (patterns).len();
@@ -1014,12 +1013,13 @@ pub fn SampleMQR(image: &BitMatrix, fp: ConcentricPattern) -> Result<QRCodeDetec
}
let mut formatInfoBits = 0;
for i in 1..=15
for info_coord in FORMAT_INFO_COORDS.iter().take(15 + 1).skip(1)
// for i in 1..=15
// for (int i = 1; i <= 15; ++i)
{
AppendBit(
&mut formatInfoBits,
image.get_point(mod2Pix.transform_point(Point::centered(FORMAT_INFO_COORDS[i]))),
image.get_point(mod2Pix.transform_point(Point::centered(*info_coord))),
);
}

View File

@@ -185,7 +185,7 @@ fn testApplyMaskPenaltyRule4() {
assert_eq!(30, mask_util::applyMaskPenaltyRule4(&matrix));
}
fn testGetDataMaskBitInternal(maskPattern: u32, expected: &Vec<Vec<u32>>) -> bool {
fn testGetDataMaskBitInternal(maskPattern: u32, expected: &[Vec<u32>]) -> bool {
for x in 0..6 {
// for (int x = 0; x < 6; ++x) {
for y in 0..6 {

View File

@@ -1,4 +1,3 @@
use std::{fmt, iter::Sum};
use std::hash::Hash;
@@ -31,20 +30,20 @@ pub type PointF = PointT<f32>;
pub type PointI = PointT<u32>;
pub type Point = PointF;
impl Into<PointI> for Point {
fn into(self) -> PointI {
impl From<Point> for PointI {
fn from(val: Point) -> Self {
PointI {
x: self.x.floor() as u32,
y: self.y.floor() as u32,
x: val.x.floor() as u32,
y: val.y.floor() as u32,
}
}
}
impl Into<Point> for PointI {
fn into(self) -> Point {
impl From<PointI> for Point {
fn from(val: PointI) -> Self {
Point {
x: self.x as f32,
y: self.y as f32,
x: val.x as f32,
y: val.y as f32,
}
}
}
@@ -81,7 +80,7 @@ where
T: Copy,
{
pub const fn new(x: T, y: T) -> PointT<T> {
PointT { x: x, y: y }
PointT { x, y }
}
pub const fn with_single(x: T) -> Self {
Self { x, y: x }