diff --git a/src/aztec/encoder/aztec_encoder.rs b/src/aztec/encoder/aztec_encoder.rs index fa54464..30da719 100644 --- a/src/aztec/encoder/aztec_encoder.rs +++ b/src/aztec/encoder/aztec_encoder.rs @@ -49,8 +49,10 @@ pub const WORD_SIZE: [u32; 33] = [ * @return Aztec symbol matrix with metadata */ pub fn encode_simple(data: &str) -> Result { - let Ok(bytes) =CharacterSet::ISO8859_1.encode_replace(data) else { - return Err(Exceptions::illegal_argument_with(format!("'{data}' cannot be encoded as ISO_8859_1"))); + let Ok(bytes) = CharacterSet::ISO8859_1.encode_replace(data) else { + return Err(Exceptions::illegal_argument_with(format!( + "'{data}' cannot be encoded as ISO_8859_1" + ))); }; encode_bytes_simple(&bytes) } diff --git a/src/aztec/encoder/state.rs b/src/aztec/encoder/state.rs index 2ba21f3..0ca0ef9 100644 --- a/src/aztec/encoder/state.rs +++ b/src/aztec/encoder/state.rs @@ -86,11 +86,9 @@ impl State { )); // throw new IllegalArgumentException("ECI code must be between 0 and 999999"); } else { - let Ok(eci_digits) = CharacterSet::ISO8859_1 - .encode(&format!("{eci}")) - else { - return Err(Exceptions::ILLEGAL_ARGUMENT) - }; + let Ok(eci_digits) = CharacterSet::ISO8859_1.encode(&format!("{eci}")) else { + return Err(Exceptions::ILLEGAL_ARGUMENT); + }; // let eciDigits = Integer.toString(eci).getBytes(StandardCharsets.ISO_8859_1); token.add(eci_digits.len() as i32, 3); // 1-6: number of ECI digits for eci_digit in &eci_digits { diff --git a/src/common/cpp_essentials/base_extentions/bitmatrix.rs b/src/common/cpp_essentials/base_extentions/bitmatrix.rs index 23ab965..4839bcb 100644 --- a/src/common/cpp_essentials/base_extentions/bitmatrix.rs +++ b/src/common/cpp_essentials/base_extentions/bitmatrix.rs @@ -29,7 +29,7 @@ impl BitMatrix { } pub fn getTopLeftOnBitWithPosition(&self, left: &mut u32, top: &mut u32) -> bool { - let Some(Point{x,y}) = self.getTopLeftOnBit() else { + let Some(Point { x, y }) = self.getTopLeftOnBit() else { return false; }; *left = x as u32; @@ -39,7 +39,7 @@ impl BitMatrix { } pub fn getBottomRightOnBitWithPosition(&self, right: &mut u32, bottom: &mut u32) -> bool { - let Some(Point{x,y}) = self.getBottomRightOnBit() else { + let Some(Point { x, y }) = self.getBottomRightOnBit() else { return false; }; *right = x as u32; diff --git a/src/common/cpp_essentials/dm_regression_line.rs b/src/common/cpp_essentials/dm_regression_line.rs index 74f4a8b..a13e94e 100644 --- a/src/common/cpp_essentials/dm_regression_line.rs +++ b/src/common/cpp_essentials/dm_regression_line.rs @@ -130,8 +130,12 @@ impl RegressionLineTrait for DMRegressionLine { } fn isHighRes(&self) -> bool { - let Some(mut min) = self.points.first().copied() else { return false }; - let Some(mut max) = self.points.first().copied() else { return false }; + let Some(mut min) = self.points.first().copied() else { + return false; + }; + let Some(mut max) = self.points.first().copied() else { + return false; + }; for p in &self.points { min.x = f32::min(min.x, p.x); min.y = f32::min(min.y, p.y); diff --git a/src/common/cpp_essentials/regression_line.rs b/src/common/cpp_essentials/regression_line.rs index 6e28d10..b1884e6 100644 --- a/src/common/cpp_essentials/regression_line.rs +++ b/src/common/cpp_essentials/regression_line.rs @@ -130,8 +130,12 @@ impl RegressionLineTrait for RegressionLine { } fn isHighRes(&self) -> bool { - let Some(mut min) = self.points.first().copied() else { return false }; - let Some(mut max) = self.points.first().copied() else { return false }; + let Some(mut min) = self.points.first().copied() else { + return false; + }; + let Some(mut max) = self.points.first().copied() else { + return false; + }; for p in &self.points { min.x = f32::min(min.x, p.x); min.y = f32::min(min.y, p.y); diff --git a/src/common/otsu_level_binarizer.rs b/src/common/otsu_level_binarizer.rs index a51c690..47d9a65 100644 --- a/src/common/otsu_level_binarizer.rs +++ b/src/common/otsu_level_binarizer.rs @@ -19,8 +19,12 @@ pub struct OtsuLevelBinarizer { impl OtsuLevelBinarizer { fn generate_threshold_matrix(source: &LS2) -> Result { let image_buffer = { - let Some(buff) : Option,Vec>> = ImageBuffer::from_vec(source.get_width() as u32, source.get_height() as u32, source.get_matrix()) else { - return Err(Exceptions::ILLEGAL_ARGUMENT) + let Some(buff): Option, Vec>> = ImageBuffer::from_vec( + source.get_width() as u32, + source.get_height() as u32, + source.get_matrix(), + ) else { + return Err(Exceptions::ILLEGAL_ARGUMENT); }; buff }; diff --git a/src/common/reedsolomon/reedsolomon_decoder.rs b/src/common/reedsolomon/reedsolomon_decoder.rs index ccc056f..c3763b1 100644 --- a/src/common/reedsolomon/reedsolomon_decoder.rs +++ b/src/common/reedsolomon/reedsolomon_decoder.rs @@ -78,7 +78,7 @@ impl ReedSolomonDecoder { return Ok(0); } let Ok(syndrome) = GenericGFPoly::new(self.field, &syndromeCoefficients) else { - return Err(Exceptions::REED_SOLOMON); + return Err(Exceptions::REED_SOLOMON); }; let sigmaOmega = self.runEuclideanAlgorithm( &GenericGF::buildMonomial(self.field, twoS as usize, 1), diff --git a/src/datamatrix/data_matrix_reader.rs b/src/datamatrix/data_matrix_reader.rs index e3a668b..15a92c0 100644 --- a/src/datamatrix/data_matrix_reader.rs +++ b/src/datamatrix/data_matrix_reader.rs @@ -181,11 +181,11 @@ impl DataMatrixReader { */ fn extractPureBits(&self, image: &BitMatrix) -> Result { let Some(leftTopBlack) = image.getTopLeftOnBit() else { - return Err(Exceptions::NOT_FOUND) - }; - let Some(rightBottomBlack) = image.getBottomRightOnBit()else { - return Err(Exceptions::NOT_FOUND) - }; + return Err(Exceptions::NOT_FOUND); + }; + let Some(rightBottomBlack) = image.getBottomRightOnBit() else { + return Err(Exceptions::NOT_FOUND); + }; let moduleSize = Self::moduleSize(leftTopBlack, image)?; diff --git a/src/datamatrix/data_matrix_writer.rs b/src/datamatrix/data_matrix_writer.rs index ac14e12..e14c904 100644 --- a/src/datamatrix/data_matrix_writer.rs +++ b/src/datamatrix/data_matrix_writer.rs @@ -119,9 +119,10 @@ impl Writer for DataMatrixWriter { let hasEncodingHint = hints.contains_key(&EncodeHintType::CHARACTER_SET); if hasEncodingHint { let Some(EncodeHintValue::CharacterSet(char_set_name)) = - hints.get(&EncodeHintType::CHARACTER_SET) else { - return Err(Exceptions::illegal_argument_with("charset does not exist")) - }; + hints.get(&EncodeHintType::CHARACTER_SET) + else { + return Err(Exceptions::illegal_argument_with("charset does not exist")); + }; charset = CharacterSet::get_character_set_by_name(char_set_name); //encoding::label::encoding_from_whatwg_label(char_set_name); // charset = Charset.forName(hints.get(EncodeHintType.CHARACTER_SET).toString()); @@ -154,9 +155,16 @@ impl Writer for DataMatrixWriter { } let symbol_lookup = SymbolInfoLookup::new(); - let Some(symbolInfo) = symbol_lookup.lookup_with_codewords_shape_size_fail(encoded.chars().count() as u32, *shape, &minSize, &maxSize, true)? else { - return Err(Exceptions::not_found_with("symbol info is bad")) - }; + let Some(symbolInfo) = symbol_lookup.lookup_with_codewords_shape_size_fail( + encoded.chars().count() as u32, + *shape, + &minSize, + &maxSize, + true, + )? + else { + return Err(Exceptions::not_found_with("symbol info is bad")); + }; //2. step: ECC generation let codewords = error_correction::encodeECC200(&encoded, symbolInfo)?; diff --git a/src/datamatrix/detector/zxing_cpp_detector/mod.rs b/src/datamatrix/detector/zxing_cpp_detector/mod.rs index e0e7683..364dd2a 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/mod.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/mod.rs @@ -1,10 +1,10 @@ mod cpp_new_detector; - use crate::common::cpp_essentials::bitmatrix_cursor_trait::*; +use crate::common::cpp_essentials::bitmatrix_cursor_trait::*; - use crate::common::cpp_essentials::dm_regression_line::*; - use crate::common::cpp_essentials::edge_tracer::*; +use crate::common::cpp_essentials::dm_regression_line::*; +use crate::common::cpp_essentials::edge_tracer::*; - use crate::common::cpp_essentials::util; +use crate::common::cpp_essentials::util; pub use cpp_new_detector::detect; diff --git a/src/datamatrix/encoder/high_level_encoder.rs b/src/datamatrix/encoder/high_level_encoder.rs index 1592180..897fd27 100644 --- a/src/datamatrix/encoder/high_level_encoder.rs +++ b/src/datamatrix/encoder/high_level_encoder.rs @@ -359,9 +359,7 @@ fn lookAheadTestIntern(msg: &str, startpos: u32, currentMode: u32) -> usize { return C40_ENCODATION; } - let Some(c) = msg - .chars() - .nth((startpos + charsProcessed) as usize) else { + let Some(c) = msg.chars().nth((startpos + charsProcessed) as usize) else { break 0; }; charsProcessed += 1; diff --git a/src/helpers.rs b/src/helpers.rs index 4f90e24..00393dd 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -116,7 +116,9 @@ pub fn detect_in_file_with_hints( hints: &mut DecodingHintDictionary, ) -> Result { let Ok(img) = image::open(file_name) else { - return Err(Exceptions::illegal_argument_with(format!("file '{file_name}' not found or cannot be opened"))); + return Err(Exceptions::illegal_argument_with(format!( + "file '{file_name}' not found or cannot be opened" + ))); }; let mut multi_format_reader = MultiFormatReader::default(); diff --git a/src/maxicode/decoder/decoded_bit_stream_parser.rs b/src/maxicode/decoder/decoded_bit_stream_parser.rs index 32146a5..a0016d7 100644 --- a/src/maxicode/decoder/decoded_bit_stream_parser.rs +++ b/src/maxicode/decoder/decoded_bit_stream_parser.rs @@ -183,7 +183,9 @@ fn getMessage(bytes: &[u8], start: u32, len: u32) -> String { // for i in start..(start+len) { // for (int i = start; i < start + len; i++) { let mut set_graphemes = SETS[set].graphemes(true); - let Some(c) = set_graphemes.nth(bytes[i as usize] as usize) else { break; }; + let Some(c) = set_graphemes.nth(bytes[i as usize] as usize) else { + break; + }; match c { LATCHA => { set = 0; diff --git a/src/maxicode/detector.rs b/src/maxicode/detector.rs index cfa8e27..25b66c5 100644 --- a/src/maxicode/detector.rs +++ b/src/maxicode/detector.rs @@ -152,8 +152,12 @@ impl Circle<'_> { *length_set = (length, rotation, points); } lengths.sort_by_key(|e| e.0); - let Some(major_axis) = lengths.last() else {return (false, PointU::default(),0,0,0)}; - let Some(minor_axis) = lengths.first() else {return (false, PointU::default(),0,0,0)}; + let Some(major_axis) = lengths.last() else { + return (false, PointU::default(), 0, 0, 0); + }; + let Some(minor_axis) = lengths.first() else { + return (false, PointU::default(), 0, 0, 0); + }; // // find foci let linear_eccentricity = ((major_axis.0 / 2).pow(2) - (minor_axis.0 / 2).pow(2)).sqrt(); @@ -305,7 +309,7 @@ impl Circle<'_> { pub fn detect(image: &BitMatrix, try_harder: bool) -> Result { // find concentric circles - let Some( mut circles) = find_concentric_circles(image) else { + let Some(mut circles) = find_concentric_circles(image) else { return Err(Exceptions::NOT_FOUND); }; @@ -328,8 +332,8 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result Result MultiFinderPatternFinder<'_> { for i3 in (i2 + 1)..size { // for (int i3 = i2 + 1; i3 < size; i3++) { - let Some( p3) = possibleCenters.get(i3) else { + let Some(p3) = possibleCenters.get(i3) else { continue; }; diff --git a/src/oned/code_128_writer.rs b/src/oned/code_128_writer.rs index f335eb9..9a0fe86 100644 --- a/src/oned/code_128_writer.rs +++ b/src/oned/code_128_writer.rs @@ -108,7 +108,11 @@ fn check(contents: &str, hints: &crate::EncodingHintDictionary) -> Result { // Check for forced code set hint. let mut forcedCodeSet = -1_i32; if hints.contains_key(&EncodeHintType::FORCE_CODE_SET) { - let Some(EncodeHintValue::ForceCodeSet(codeSetHint)) = hints.get(&EncodeHintType::FORCE_CODE_SET) else { return Err(Exceptions::ILLEGAL_STATE) }; + let Some(EncodeHintValue::ForceCodeSet(codeSetHint)) = + hints.get(&EncodeHintType::FORCE_CODE_SET) + else { + return Err(Exceptions::ILLEGAL_STATE); + }; match codeSetHint.as_str() { "A" => forcedCodeSet = CODE_CODE_A as i32, "B" => forcedCodeSet = CODE_CODE_B as i32, diff --git a/src/oned/code_39_writer.rs b/src/oned/code_39_writer.rs index a4ab191..7324adc 100644 --- a/src/oned/code_39_writer.rs +++ b/src/oned/code_39_writer.rs @@ -71,8 +71,13 @@ impl OneDimensionalCodeWriter for Code39Writer { pos += Self::appendPattern(&mut result, pos as usize, &narrowWhite, false); //append next character to byte matrix for i in 0..length { - let Some(indexInString) = Code39Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?) else { - continue; + let Some(indexInString) = Code39Reader::ALPHABET_STRING.find( + contents + .chars() + .nth(i) + .ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?, + ) else { + continue; }; Self::toIntArray( Code39Reader::CHARACTER_ENCODINGS[indexInString], diff --git a/src/oned/code_93_writer.rs b/src/oned/code_93_writer.rs index c92c94f..518b066 100644 --- a/src/oned/code_93_writer.rs +++ b/src/oned/code_93_writer.rs @@ -49,7 +49,14 @@ impl OneDimensionalCodeWriter for Code93Writer { for i in 0..length { // for (int i = 0; i < length; i++) { - let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?) else {panic!("alphabet")}; + let Some(indexInString) = Code93Reader::ALPHABET_STRING.find( + contents + .chars() + .nth(i) + .ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?, + ) else { + panic!("alphabet") + }; pos += Self::appendPattern( &mut result, pos, @@ -132,7 +139,11 @@ impl Code93Writer { for i in (0..contents.chars().count()).rev() { // for (int i = contents.length() - 1; i >= 0; i--) { - let Some(indexInString) = Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).unwrap()) else {panic!("not in the alphabet");}; + let Some(indexInString) = + Code93Reader::ALPHABET_STRING.find(contents.chars().nth(i).unwrap()) + else { + panic!("not in the alphabet"); + }; total += indexInString as u32 * weight; weight += 1; if weight > maxWeight { diff --git a/src/oned/one_d_reader.rs b/src/oned/one_d_reader.rs index bf27191..ec2c7bc 100644 --- a/src/oned/one_d_reader.rs +++ b/src/oned/one_d_reader.rs @@ -105,7 +105,7 @@ pub trait OneDReader: Reader { } } let Ok(mut result) = self.decode_row(row_number as u32, &row, &hints) else { - continue + continue; }; // We found our barcode if attempt == 1 { diff --git a/src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs b/src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs index 66f1584..d613058 100644 --- a/src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs +++ b/src/oned/rss/expanded/rss_expanded_image_2_result_test_case.rs @@ -87,8 +87,10 @@ fn assertCorrectImage2result(fileName: &str, expected: ExpandedProductParsedRXin theRXingResult.getBarcodeFormat() ); - let ParsedClientResult::ExpandedProductResult(result) = crate::client::result::parseRXingResult(&theRXingResult) else { - panic!("incorrect result type found"); + let ParsedClientResult::ExpandedProductResult(result) = + crate::client::result::parseRXingResult(&theRXingResult) + else { + panic!("incorrect result type found"); }; assert_eq!(expected, result); diff --git a/src/pdf417/decoder/decoded_bit_stream_parser.rs b/src/pdf417/decoder/decoded_bit_stream_parser.rs index 4ef124b..dfff14e 100644 --- a/src/pdf417/decoder/decoded_bit_stream_parser.rs +++ b/src/pdf417/decoder/decoded_bit_stream_parser.rs @@ -267,7 +267,7 @@ pub fn decodeMacroBlock( MACRO_PDF417_OPTIONAL_FIELD_CHECKSUM => { let mut checksum = ECIStringBuilder::default(); codeIndex = numericCompaction(codewords, codeIndex + 1, &mut checksum)?; - let Ok(parsed_checksum ) = checksum.to_string().parse() else { + let Ok(parsed_checksum) = checksum.to_string().parse() else { return Err(Exceptions::FORMAT); }; resultMetadata.setChecksum(parsed_checksum); @@ -275,7 +275,7 @@ pub fn decodeMacroBlock( MACRO_PDF417_OPTIONAL_FIELD_FILE_SIZE => { let mut fileSize = ECIStringBuilder::default(); codeIndex = numericCompaction(codewords, codeIndex + 1, &mut fileSize)?; - let Ok(parsed_file_size)= fileSize.to_string().parse() else { + let Ok(parsed_file_size) = fileSize.to_string().parse() else { return Err(Exceptions::FORMAT); }; resultMetadata.setFileSize(parsed_file_size); diff --git a/src/qrcode/cpp_port/decoder.rs b/src/qrcode/cpp_port/decoder.rs index eb558f7..12aab65 100644 --- a/src/qrcode/cpp_port/decoder.rs +++ b/src/qrcode/cpp_port/decoder.rs @@ -392,12 +392,12 @@ pub fn DecodeBitStream( pub fn Decode(bits: &BitMatrix) -> Result> { let Ok(pversion) = ReadVersion(bits) else { - return Err(Exceptions::format_with("Invalid version")) + return Err(Exceptions::format_with("Invalid version")); }; let version = pversion; let Ok(formatInfo) = ReadFormatInformation(bits, version.isMicroQRCode()) else { - return Err(Exceptions::format_with("Invalid format information")) + return Err(Exceptions::format_with("Invalid format information")); }; // Read codewords diff --git a/src/qrcode/detector/finder_pattern_finder.rs b/src/qrcode/detector/finder_pattern_finder.rs index eeeaca4..e6d746b 100755 --- a/src/qrcode/detector/finder_pattern_finder.rs +++ b/src/qrcode/detector/finder_pattern_finder.rs @@ -717,7 +717,7 @@ impl<'a> FinderPatternFinder<'_> { let minModuleSize = fpi.getEstimatedModuleSize(); for j in (i + 1)..(self.possibleCenters.len() - 1) { - let Some(fpj) = self.possibleCenters.get(j) else { + let Some(fpj) = self.possibleCenters.get(j) else { return Err(Exceptions::NOT_FOUND); }; let squares0 = Self::squaredDistance(fpi, fpj); diff --git a/src/svg_luminance_source.rs b/src/svg_luminance_source.rs index 390ce10..dcd7ab8 100644 --- a/src/svg_luminance_source.rs +++ b/src/svg_luminance_source.rs @@ -52,10 +52,15 @@ impl SVGLuminanceSource { pub fn new(svg_data: &[u8]) -> Result { // Load the SVG file let Ok(tree) = resvg::usvg::Tree::from_data(svg_data, &Options::default()) else { - return Err(Exceptions::format_with(format!("could not parse svg data: {}", "err"))); + return Err(Exceptions::format_with(format!( + "could not parse svg data: {}", + "err" + ))); }; - let Some(mut pixmap) = resvg::tiny_skia::Pixmap::new(tree.size.width() as u32, tree.size.height() as u32) else { + let Some(mut pixmap) = + resvg::tiny_skia::Pixmap::new(tree.size.width() as u32, tree.size.height() as u32) + else { return Err(Exceptions::format_with("could not create pixmap")); }; @@ -63,9 +68,13 @@ impl SVGLuminanceSource { tree_resvg.render(resvg::tiny_skia::Transform::default(), &mut pixmap.as_mut()); - let Some(buffer) = RgbaImage::from_raw(tree.size.width() as u32, tree.size.height() as u32, pixmap.data().to_vec()) else { - return Err(Exceptions::format_with("could not create image buffer")); - }; + let Some(buffer) = RgbaImage::from_raw( + tree.size.width() as u32, + tree.size.height() as u32, + pixmap.data().to_vec(), + ) else { + return Err(Exceptions::format_with("could not create image buffer")); + }; // let Ok(image) = image::load_from_memory_with_format(pixmap.data(), image::ImageFormat::Bmp) else { // return Err(Exceptions::format("could not generate image"));