diff --git a/crates/one-d-proc-derive/src/lib.rs b/crates/one-d-proc-derive/src/lib.rs index 92d2ccb..59ac4f1 100644 --- a/crates/one-d-proc-derive/src/lib.rs +++ b/crates/one-d-proc-derive/src/lib.rs @@ -1,6 +1,5 @@ use proc_macro::TokenStream; use quote::quote; -use syn; #[proc_macro_derive(OneDReader)] pub fn one_d_reader_derive(input: TokenStream) -> TokenStream { diff --git a/src/binary_bitmap.rs b/src/binary_bitmap.rs index a17f900..f4882b6 100644 --- a/src/binary_bitmap.rs +++ b/src/binary_bitmap.rs @@ -142,10 +142,10 @@ impl BinaryBitmap { .binarizer .get_luminance_source() .crop(left, top, width, height); - return BinaryBitmap::new( + BinaryBitmap::new( self.binarizer .create_binarizer(newSource.expect("new lum source expected")), - ); + ) } /** @@ -168,10 +168,10 @@ impl BinaryBitmap { .binarizer .get_luminance_source() .rotate_counter_clockwise(); - return BinaryBitmap::new( + BinaryBitmap::new( self.binarizer .create_binarizer(newSource.expect("new lum source expected")), - ); + ) } /** @@ -187,10 +187,10 @@ impl BinaryBitmap { .binarizer .get_luminance_source() .rotate_counter_clockwise_45(); - return BinaryBitmap::new( + BinaryBitmap::new( self.binarizer .create_binarizer(newSource.expect("new lum source expected")), - ); + ) } } diff --git a/src/pdf417/decoder/detection_result_column.rs b/src/pdf417/decoder/detection_result_column.rs index 3164f2b..bdeb0ea 100644 --- a/src/pdf417/decoder/detection_result_column.rs +++ b/src/pdf417/decoder/detection_result_column.rs @@ -21,7 +21,7 @@ use super::{BoundingBox, Codeword, DetectionRXingResultRowIndicatorColumn}; const MAX_NEARBY_DISTANCE: u32 = 5; pub trait DetectionRXingResultColumnTrait { - fn new(boundingBox: Rc) -> DetectionRXingResultColumn + fn new_column(boundingBox: Rc) -> DetectionRXingResultColumn where Self: Sized; fn new_with_is_left(boundingBox: Rc, isLeft: bool) -> DetectionRXingResultColumn @@ -48,7 +48,7 @@ pub struct DetectionRXingResultColumn { } impl DetectionRXingResultColumnTrait for DetectionRXingResultColumn { - fn new(boundingBox: Rc) -> DetectionRXingResultColumn { + fn new_column(boundingBox: Rc) -> DetectionRXingResultColumn { DetectionRXingResultColumn { boundingBox: BoundingBox::from_other(boundingBox.clone()), codewords: vec![None; (boundingBox.getMaxY() - boundingBox.getMinY() + 1) as usize], diff --git a/src/pdf417/decoder/pdf_417_scanning_decoder.rs b/src/pdf417/decoder/pdf_417_scanning_decoder.rs index c526062..f6593b3 100644 --- a/src/pdf417/decoder/pdf_417_scanning_decoder.rs +++ b/src/pdf417/decoder/pdf_417_scanning_decoder.rs @@ -44,9 +44,9 @@ const MAX_EC_CODEWORDS: u32 = 512; // than it should be. This can happen if the scanner used a bad blackpoint. pub fn decode( image: &BitMatrix, - imageTopLeft: Option, + image_top_left: Option, imageBottomLeft: Option, - imageTopRight: Option, + image_top_right: Option, imageBottomRight: Option, minCodewordWidth: u32, maxCodewordWidth: u32, @@ -55,30 +55,30 @@ pub fn decode( let mut maxCodewordWidth = maxCodewordWidth; let mut boundingBox = Rc::new(BoundingBox::new( Rc::new(image.clone()), - imageTopLeft, + image_top_left, imageBottomLeft, - imageTopRight, + image_top_right, imageBottomRight, )?); let mut leftRowIndicatorColumn = None; let mut rightRowIndicatorColumn = None; let mut detectionRXingResult = None; for firstPass in [true, false] { - if imageTopLeft.is_some() { + if let Some(image_top_left) = image_top_left { leftRowIndicatorColumn = Some(getRowIndicatorColumn( image, boundingBox.clone(), - imageTopLeft.unwrap(), + image_top_left, true, minCodewordWidth, maxCodewordWidth, )); } - if imageTopRight.is_some() { + if let Some(image_top_right) = image_top_right { rightRowIndicatorColumn = Some(getRowIndicatorColumn( image, boundingBox.clone(), - imageTopRight.unwrap(), + image_top_right, false, minCodewordWidth, maxCodewordWidth, @@ -129,7 +129,7 @@ pub fn decode( { DetectionRXingResultColumn::new_with_is_left(boundingBox.clone(), barcodeColumn == 0) } else { - DetectionRXingResultColumn::new(boundingBox.clone()) + DetectionRXingResultColumn::new_column(boundingBox.clone()) }; detectionRXingResult diff --git a/src/pdf417/encoder/pdf_417_high_level_encoder.rs b/src/pdf417/encoder/pdf_417_high_level_encoder.rs index b35144f..e865347 100644 --- a/src/pdf417/encoder/pdf_417_high_level_encoder.rs +++ b/src/pdf417/encoder/pdf_417_high_level_encoder.rs @@ -217,11 +217,15 @@ pub fn encodeHighLevel( // User selected encoding mode match compaction { Compaction::TEXT => { - encodeText(&input, p, len as u32, &mut sb, textSubMode)?; - } - Compaction::BYTE if autoECI => { - encodeMultiECIBinary(&input, 0, input.length() as u32, TEXT_COMPACTION, &mut sb)? + encodeText(input.as_ref(), p, len as u32, &mut sb, textSubMode)?; } + Compaction::BYTE if autoECI => encodeMultiECIBinary( + input.as_ref(), + 0, + input.length() as u32, + TEXT_COMPACTION, + &mut sb, + )?, Compaction::BYTE => { let msgBytes = encoding .as_ref() @@ -238,7 +242,7 @@ pub fn encodeHighLevel( } Compaction::NUMERIC => { sb.push(char::from_u32(LATCH_TO_NUMERIC).ok_or(Exceptions::PARSE)?); - encodeNumeric(&input, p, len as u32, &mut sb)?; + encodeNumeric(input.as_ref(), p, len as u32, &mut sb)?; } _ => { let mut encodingMode = TEXT_COMPACTION; //Default mode, see 4.4.2.1 @@ -250,26 +254,26 @@ pub fn encodeHighLevel( if p >= len as u32 { break; } - let n = determineConsecutiveDigitCount(&input, p)?; + let n = determineConsecutiveDigitCount(input.as_ref(), p)?; if n >= 13 { sb.push(char::from_u32(LATCH_TO_NUMERIC).ok_or(Exceptions::PARSE)?); encodingMode = NUMERIC_COMPACTION; textSubMode = SUBMODE_ALPHA; //Reset after latch - encodeNumeric(&input, p, n, &mut sb)?; + encodeNumeric(input.as_ref(), p, n, &mut sb)?; p += n; } else { - let t = determineConsecutiveTextCount(&input, p)?; + let t = determineConsecutiveTextCount(input.as_ref(), p)?; if t >= 5 || n == len as u32 { if encodingMode != TEXT_COMPACTION { sb.push(char::from_u32(LATCH_TO_TEXT).ok_or(Exceptions::PARSE)?); encodingMode = TEXT_COMPACTION; textSubMode = SUBMODE_ALPHA; //start with submode alpha after latch } - textSubMode = encodeText(&input, p, t, &mut sb, textSubMode)?; + textSubMode = encodeText(input.as_ref(), p, t, &mut sb, textSubMode)?; p += t; } else { let mut b = determineConsecutiveBinaryCount( - &input, + input.as_ref(), p, if autoECI { None } else { encoding }, )?; @@ -298,7 +302,13 @@ pub fn encodeHighLevel( if (bytes_ok && b == 1) && (encodingMode == TEXT_COMPACTION) { //Switch for one byte (instead of latch) if autoECI { - encodeMultiECIBinary(&input, p, 1, TEXT_COMPACTION, &mut sb)?; + encodeMultiECIBinary( + input.as_ref(), + p, + 1, + TEXT_COMPACTION, + &mut sb, + )?; } else { encodeBinary( bytes.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?, @@ -311,7 +321,13 @@ pub fn encodeHighLevel( } else { //Mode latch performed by encodeBinary() if autoECI { - encodeMultiECIBinary(&input, p, p + b, encodingMode, &mut sb)?; + encodeMultiECIBinary( + input.as_ref(), + p, + p + b, + encodingMode, + &mut sb, + )?; } else { encodeBinary( bytes.as_ref().ok_or(Exceptions::ILLEGAL_STATE)?, @@ -346,7 +362,7 @@ pub fn encodeHighLevel( * @return the text submode in which this method ends */ fn encodeText( - input: &Box, + input: &T, startpos: u32, count: u32, sb: &mut String, @@ -491,7 +507,7 @@ fn encodeText( * @param sb receives the encoded codewords */ fn encodeMultiECIBinary( - input: &Box, + input: &T, startpos: u32, count: u32, startmode: u32, @@ -535,7 +551,7 @@ fn encodeMultiECIBinary( Ok(()) } -pub fn subBytes(input: &Box, start: u32, end: u32) -> Result> { +pub fn subBytes(input: &T, start: u32, end: u32) -> Result> { let count = (end - start) as usize; let mut result = vec![0_u8; count]; for i in start as usize..end as usize { @@ -598,7 +614,7 @@ fn encodeBinary( } fn encodeNumeric( - input: &Box, + input: &T, startpos: u32, count: u32, sb: &mut String, @@ -679,10 +695,7 @@ fn isText(ch: char) -> bool { * @param startpos the start position within the input * @return the requested character count */ -fn determineConsecutiveDigitCount( - input: &Box, - startpos: u32, -) -> Result { +fn determineConsecutiveDigitCount(input: &T, startpos: u32) -> Result { let mut count = 0; let len = input.length(); let mut idx = startpos as usize; @@ -703,10 +716,7 @@ fn determineConsecutiveDigitCount( * @param startpos the start position within the input * @return the requested character count */ -fn determineConsecutiveTextCount( - input: &Box, - startpos: u32, -) -> Result { +fn determineConsecutiveTextCount(input: &T, startpos: u32) -> Result { let len = input.length(); let mut idx = startpos as usize; while idx < len { @@ -745,7 +755,7 @@ fn determineConsecutiveTextCount( * @return the requested character count */ fn determineConsecutiveBinaryCount( - input: &Box, + input: &T, startpos: u32, encoding: Option, ) -> Result { diff --git a/src/qrcode/encoder/minimal_encoder.rs b/src/qrcode/encoder/minimal_encoder.rs index a367701..24e14b4 100644 --- a/src/qrcode/encoder/minimal_encoder.rs +++ b/src/qrcode/encoder/minimal_encoder.rs @@ -846,7 +846,7 @@ impl RXingResultList { result } - fn internal_static_get_size(version: VersionRef, list: &Vec) -> u32 { + fn internal_static_get_size(version: VersionRef, list: &[RXingResultNode]) -> u32 { let result = list.iter().fold(0, |acc, node| acc + node.getSize(version)); result } diff --git a/src/svg_luminance_source.rs b/src/svg_luminance_source.rs index fda0196..e21c7dc 100644 --- a/src/svg_luminance_source.rs +++ b/src/svg_luminance_source.rs @@ -27,7 +27,7 @@ impl LuminanceSource for SVGLuminanceSource { } fn crop(&self, left: usize, top: usize, width: usize, height: usize) -> Result { - self.0.crop(left, top, width, height).map(|src| Self(src)) + self.0.crop(left, top, width, height).map(Self) } fn is_rotate_supported(&self) -> bool { @@ -39,11 +39,11 @@ impl LuminanceSource for SVGLuminanceSource { } fn rotate_counter_clockwise(&self) -> Result { - self.0.rotate_counter_clockwise().map(|src| Self(src)) + self.0.rotate_counter_clockwise().map(Self) } fn rotate_counter_clockwise_45(&self) -> Result { - self.0.rotate_counter_clockwise_45().map(|src| Self(src)) + self.0.rotate_counter_clockwise_45().map(Self) } }