From 9a5d6a704ba65b5dc0ebc36fc114c9221e88af70 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 4 Jan 2023 18:29:08 -0600 Subject: [PATCH] clippy fix --- src/common/StringUtilsTestCase.rs | 12 ++++++------ src/helpers.rs | 24 ++++++++---------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/common/StringUtilsTestCase.rs b/src/common/StringUtilsTestCase.rs index a7b08ed..e8cf00e 100644 --- a/src/common/StringUtilsTestCase.rs +++ b/src/common/StringUtilsTestCase.rs @@ -47,7 +47,7 @@ fn test_random() { fn test_short_shift_jis1() { // 金魚 do_test( - &vec![0x8b, 0xe0, 0x8b, 0x9b], + &[0x8b, 0xe0, 0x8b, 0x9b], encoding::label::encoding_from_whatwg_label("SJIS").unwrap(), "SJIS", ); @@ -57,7 +57,7 @@ fn test_short_shift_jis1() { fn test_short_iso885911() { // båd do_test( - &vec![0x62, 0xe5, 0x64], + &[0x62, 0xe5, 0x64], encoding::all::ISO_8859_1, "ISO8859_1", ); @@ -67,7 +67,7 @@ fn test_short_iso885911() { fn test_short_utf8() { // Español do_test( - &vec![0x45, 0x73, 0x70, 0x61, 0xc3, 0xb1, 0x6f, 0x6c], + &[0x45, 0x73, 0x70, 0x61, 0xc3, 0xb1, 0x6f, 0x6c], encoding::all::UTF_8, "UTF8", ); @@ -77,7 +77,7 @@ fn test_short_utf8() { fn test_mixed_shift_jis1() { // Hello 金! do_test( - &vec![0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x8b, 0xe0, 0x21], + &[0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x8b, 0xe0, 0x21], encoding::label::encoding_from_whatwg_label("SJIS").unwrap(), "SJIS", ); @@ -87,7 +87,7 @@ fn test_mixed_shift_jis1() { fn test_utf16_be() { // 调压柜 do_test( - &vec![0xFE, 0xFF, 0x8c, 0x03, 0x53, 0x8b, 0x67, 0xdc], + &[0xFE, 0xFF, 0x8c, 0x03, 0x53, 0x8b, 0x67, 0xdc], encoding::all::UTF_16BE, encoding::all::UTF_16BE.name(), ); @@ -97,7 +97,7 @@ fn test_utf16_be() { fn test_utf16_le() { // 调压柜 do_test( - &vec![0xFF, 0xFE, 0x03, 0x8c, 0x8b, 0x53, 0xdc, 0x67], + &[0xFF, 0xFE, 0x03, 0x8c, 0x8b, 0x53, 0xdc, 0x67], encoding::all::UTF_16LE, encoding::all::UTF_16LE.name(), ); diff --git a/src/helpers.rs b/src/helpers.rs index 0c198c9..2c78b33 100644 --- a/src/helpers.rs +++ b/src/helpers.rs @@ -36,15 +36,13 @@ pub fn detect_in_file_with_hints( ); } - if !hints.contains_key(&DecodeHintType::TRY_HARDER) { - hints.insert(DecodeHintType::TRY_HARDER, DecodeHintValue::TryHarder(true)); - } + hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); multi_format_reader.decode_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( BufferedImageLuminanceSource::new(img), ))))), - &hints, + hints, ) } @@ -62,15 +60,13 @@ pub fn detect_multiple_in_file_with_hints( let multi_format_reader = MultiFormatReader::default(); let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader); - if !hints.contains_key(&DecodeHintType::TRY_HARDER) { - hints.insert(DecodeHintType::TRY_HARDER, DecodeHintValue::TryHarder(true)); - } + hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); scanner.decode_multiple_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( BufferedImageLuminanceSource::new(img), ))))), - &hints, + hints, ) } @@ -99,15 +95,13 @@ pub fn detect_in_luma_with_hints( ); } - if !hints.contains_key(&DecodeHintType::TRY_HARDER) { - hints.insert(DecodeHintType::TRY_HARDER, DecodeHintValue::TryHarder(true)); - } + hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); multi_format_reader.decode_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( Luma8LuminanceSource::new(luma, width, height), ))))), - &hints, + hints, ) } @@ -128,14 +122,12 @@ pub fn detect_multiple_in_luma_with_hints( let multi_format_reader = MultiFormatReader::default(); let mut scanner = GenericMultipleBarcodeReader::new(multi_format_reader); - if !hints.contains_key(&DecodeHintType::TRY_HARDER) { - hints.insert(DecodeHintType::TRY_HARDER, DecodeHintValue::TryHarder(true)); - } + hints.entry(DecodeHintType::TRY_HARDER).or_insert(DecodeHintValue::TryHarder(true)); scanner.decode_multiple_with_hints( &mut BinaryBitmap::new(Rc::new(RefCell::new(HybridBinarizer::new(Box::new( Luma8LuminanceSource::new(luma, width, height), ))))), - &hints, + hints, ) }