diff --git a/src/common/cpp_essentials/decoder_result.rs b/src/common/cpp_essentials/decoder_result.rs index 3504747e..561475bf 100644 --- a/src/common/cpp_essentials/decoder_result.rs +++ b/src/common/cpp_essentials/decoder_result.rs @@ -1,4 +1,4 @@ -use std::rc::Rc; +use std::sync::Arc; use crate::{common::ECIStringBuilder, Exceptions}; @@ -19,7 +19,7 @@ where //Error _error; //std::shared_ptr _extra; error: Option, - extra: Rc, + extra: Arc, } impl Default for DecoderResult @@ -135,13 +135,13 @@ where self } - pub fn extra(&self) -> Rc { + pub fn extra(&self) -> Arc { self.extra.clone() } - pub fn setExtra(&mut self, extra: Rc) { + pub fn setExtra(&mut self, extra: Arc) { self.extra = extra } - pub fn withExtra(mut self, extra: Rc) -> DecoderResult { + pub fn withExtra(mut self, extra: Arc) -> DecoderResult { self.setExtra(extra); self } diff --git a/src/common/cpp_essentials/edge_tracer.rs b/src/common/cpp_essentials/edge_tracer.rs index 309d7c77..70af32e2 100644 --- a/src/common/cpp_essentials/edge_tracer.rs +++ b/src/common/cpp_essentials/edge_tracer.rs @@ -1,4 +1,4 @@ -use std::{cell::RefCell, rc::Rc}; +use std::sync::{Arc, RwLock}; use crate::{ common::{BitMatrix, Result}, @@ -16,7 +16,7 @@ pub struct EdgeTracer<'a> { d: Point, // current direction // pub history: Option<&'a mut ByteMatrix>, // = nullptr; - pub history: Option>>, + pub history: Option>>, pub state: i32, // const BitMatrix* img; @@ -229,16 +229,22 @@ impl<'a> EdgeTracer<'_> { // if (self.history && maxStepSize == 1) { if let Some(history) = &self.history { if maxStepSize == 1 { - if history.borrow().get(self.p.x as u32, self.p.y as u32) + if history + .read() + .map_err(|_| { + Exceptions::illegal_state_with("Failed to acquire read lock") + })? + .get(self.p.x as u32, self.p.y as u32) == self.state as u8 { return Ok(StepResult::ClosedEnd); } - history.borrow_mut().set( - self.p.x as u32, - self.p.y as u32, - self.state as u8, - ); + history + .write() + .map_err(|_| { + Exceptions::illegal_state_with("Failed to acquire write lock") + })? + .set(self.p.x as u32, self.p.y as u32, self.state as u8); } } diff --git a/src/common/decoder_rxing_result.rs b/src/common/decoder_rxing_result.rs index 9983923c..5bd71f64 100644 --- a/src/common/decoder_rxing_result.rs +++ b/src/common/decoder_rxing_result.rs @@ -18,7 +18,7 @@ // import java.util.List; -use std::{any::Any, rc::Rc}; +use std::{any::Any, sync::Arc}; /** *

Encapsulates the result of decoding a matrix of bits. This typically @@ -35,7 +35,7 @@ pub struct DecoderRXingResult { ecLevel: String, errorsCorrected: usize, erasures: usize, - other: Option>, + other: Option>, structuredAppendParity: i32, structuredAppendSequenceNumber: i32, symbologyModifier: u32, @@ -203,11 +203,11 @@ impl DecoderRXingResult { /** * @return arbitrary additional metadata */ - pub fn getOther(&self) -> Option> { + pub fn getOther(&self) -> Option> { self.other.clone() } - pub fn setOther(&mut self, other: Option>) { + pub fn setOther(&mut self, other: Option>) { self.other = other } diff --git a/src/common/minimal_eci_input.rs b/src/common/minimal_eci_input.rs index eeabf726..761901b4 100644 --- a/src/common/minimal_eci_input.rs +++ b/src/common/minimal_eci_input.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::{fmt, rc::Rc}; +use std::{fmt, sync::Arc}; use unicode_segmentation::UnicodeSegmentation; @@ -250,7 +250,7 @@ impl MinimalECIInput { Ok(self.bytes[index] == 1000) } - fn addEdge(edges: &mut [Vec>>], to: usize, edge: Rc) { + fn addEdge(edges: &mut [Vec>>], to: usize, edge: Arc) { if edges[to][edge.encoderIndex].is_none() || edges[to][edge.encoderIndex] // .clone() @@ -266,9 +266,9 @@ impl MinimalECIInput { fn addEdges( stringToEncode: &str, encoderSet: &ECIEncoderSet, - edges: &mut [Vec>>], + edges: &mut [Vec>>], from: usize, - previous: Option>, + previous: Option>, fnc1: Option<&str>, ) { // let ch = stringToEncode.chars().nth(from).unwrap() as i16; @@ -298,7 +298,7 @@ impl MinimalECIInput { Self::addEdge( edges, from + 1, - Rc::new(InputEdge::new(ch, encoderSet, i, previous.clone(), fnc1)), + Arc::new(InputEdge::new(ch, encoderSet, i, previous.clone(), fnc1)), ); } } @@ -383,7 +383,7 @@ impl MinimalECIInput { struct InputEdge { c: String, encoderIndex: usize, //the encoding of this edge - previous: Option>, + previous: Option>, cachedTotalSize: usize, } impl InputEdge { @@ -393,7 +393,7 @@ impl InputEdge { c: &str, encoderSet: &ECIEncoderSet, encoderIndex: usize, - previous: Option>, + previous: Option>, fnc1: Option<&str>, ) -> Self { let mut size = if c == Self::FNC1_UNICODE { diff --git a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs index a7e067f2..d2994131 100644 --- a/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs +++ b/src/datamatrix/detector/zxing_cpp_detector/cpp_new_detector.rs @@ -11,12 +11,12 @@ macro_rules! CHECK { */ // SPDX-License-Identifier: Apache-2.0 -use std::{cell::RefCell, rc::Rc}; +use std::sync::{Arc, RwLock}; use crate::{ common::{ - cpp_essentials::RegressionLineTrait, BitMatrix, DefaultGridSampler, - GridSampler, Quadrilateral, Result, + cpp_essentials::RegressionLineTrait, BitMatrix, DefaultGridSampler, GridSampler, + Quadrilateral, Result, }, datamatrix::detector::{ zxing_cpp_detector::{util::intersect, BitMatrixCursorTrait}, @@ -262,7 +262,7 @@ pub fn detect( // a history log to remember where the tracing already passed by to prevent a later trace from doing the same work twice let mut history = None; if tryHarder { - history = Some(Rc::new(RefCell::new(ByteMatrix::new( + history = Some(Arc::new(RwLock::new(ByteMatrix::new( image.getWidth(), image.getHeight(), )))); @@ -292,7 +292,10 @@ pub fn detect( let startPos = Point::centered(center - center * dir + MIN_SYMBOL_SIZE as i32 / 2 * dir); if let Some(history) = &mut history { - history.borrow_mut().clear(0); + history + .write() + .map_err(|_| Exceptions::illegal_state_with("Failed to acquire write lock"))? + .clear(0); // history.clear(0); } diff --git a/src/datamatrix/encoder/encoder_context.rs b/src/datamatrix/encoder/encoder_context.rs index 3a1658c9..08ed35f5 100644 --- a/src/datamatrix/encoder/encoder_context.rs +++ b/src/datamatrix/encoder/encoder_context.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::rc::Rc; +use std::sync::Arc; use crate::common::{CharacterSet, Result}; use crate::{Dimension, Exceptions}; @@ -24,7 +24,7 @@ use super::{SymbolInfo, SymbolInfoLookup, SymbolShapeHint}; const ISO_8859_1_ENCODER: CharacterSet = CharacterSet::ISO8859_1; pub struct EncoderContext<'a> { - symbol_lookup: Rc>, + symbol_lookup: Arc>, msg: String, shape: SymbolShapeHint, minSize: Option, @@ -39,7 +39,7 @@ pub struct EncoderContext<'a> { impl<'a> EncoderContext<'_> { pub fn with_symbol_info_lookup( msg: &str, - symbol_lookup: Rc>, + symbol_lookup: Arc>, ) -> Result> { let mut new_self = EncoderContext::new(msg)?; new_self.symbol_lookup = symbol_lookup.clone(); @@ -67,7 +67,7 @@ impl<'a> EncoderContext<'_> { )); }; Ok(Self { - symbol_lookup: Rc::new(SymbolInfoLookup::new()), + symbol_lookup: Arc::new(SymbolInfoLookup::new()), msg: sb, shape: SymbolShapeHint::FORCE_NONE, codewords: String::with_capacity(msg.chars().count()), diff --git a/src/datamatrix/encoder/high_level_encode_test_case.rs b/src/datamatrix/encoder/high_level_encode_test_case.rs index 2e563a4f..b586d8cb 100644 --- a/src/datamatrix/encoder/high_level_encode_test_case.rs +++ b/src/datamatrix/encoder/high_level_encode_test_case.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::rc::Rc; +use std::sync::Arc; use once_cell::sync::Lazy; @@ -121,7 +121,7 @@ fn testC40EncodationSpecialCases1() { let substitute_symbols = SymbolInfoLookup::new(); let substitute_symbols = useTestSymbols(substitute_symbols); - let sil = Rc::new(substitute_symbols); + let sil = Arc::new(substitute_symbols); let visualized = encodeHighLevelCompareSIL("AIMAIMAIMAIMAIMAIM", false, Some(sil.clone())); assert_eq!("230 91 11 91 11 91 11 91 11 91 11 91 11", visualized); @@ -136,7 +136,7 @@ fn testC40EncodationSpecialCases1() { //case "c": Unlatch and write last character in ASCII let substitute_symbols = resetSymbols(substitute_symbols); - let sil = Rc::new(substitute_symbols); + let sil = Arc::new(substitute_symbols); let visualized = encodeHighLevelSIL("AIMAIMAIMAIMAIMAI", sil.clone()); assert_eq!( @@ -565,14 +565,14 @@ fn encodeHighLevel(msg: &str) -> String { encodeHighLevelCompare(msg, true) } -fn encodeHighLevelSIL(msg: &str, sil: Rc) -> String { +fn encodeHighLevelSIL(msg: &str, sil: Arc) -> String { encodeHighLevelCompareSIL(msg, true, Some(sil)) } fn encodeHighLevelCompareSIL( msg: &str, compareSizeToMinimalEncoder: bool, - sil: Option>, + sil: Option>, ) -> String { let encoded = high_level_encoder::encodeHighLevelSIL(msg, sil).expect("encodes"); let encoded2 = minimal_encoder::encodeHighLevel(msg).expect("encodes"); diff --git a/src/datamatrix/encoder/high_level_encoder.rs b/src/datamatrix/encoder/high_level_encoder.rs index 13f7e2b9..e293b1d4 100644 --- a/src/datamatrix/encoder/high_level_encoder.rs +++ b/src/datamatrix/encoder/high_level_encoder.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::rc::Rc; +use std::sync::Arc; use crate::common::{CharacterSet, Result}; use crate::{Dimension, Exceptions}; @@ -146,7 +146,7 @@ pub fn encodeHighLevel(msg: &str) -> Result { */ pub fn encodeHighLevelSIL( msg: &str, - symbol_lookup: Option>, + symbol_lookup: Option>, ) -> Result { encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup( msg, @@ -184,17 +184,17 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup( minSize: Option, maxSize: Option, forceC40: bool, - symbol_lookup: Option>, + symbol_lookup: Option>, ) -> Result { //the codewords 0..255 are encoded as Unicode characters - let c40Encoder = Rc::new(C40Encoder::new()); - let encoders: [Rc; 6] = [ - Rc::new(ASCIIEncoder::new()), + let c40Encoder = Arc::new(C40Encoder::new()); + let encoders: [Arc; 6] = [ + Arc::new(ASCIIEncoder::new()), c40Encoder.clone(), - Rc::new(TextEncoder::new()), - Rc::new(X12Encoder::new()), - Rc::new(EdifactEncoder::new()), - Rc::new(Base256Encoder::new()), + Arc::new(TextEncoder::new()), + Arc::new(X12Encoder::new()), + Arc::new(EdifactEncoder::new()), + Arc::new(Base256Encoder::new()), ]; let mut context = if let Some(symbol_table) = symbol_lookup { diff --git a/src/datamatrix/encoder/minimal_encoder.rs b/src/datamatrix/encoder/minimal_encoder.rs index 33d3af71..30bc3dd1 100755 --- a/src/datamatrix/encoder/minimal_encoder.rs +++ b/src/datamatrix/encoder/minimal_encoder.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::{fmt, rc::Rc}; +use std::{fmt, sync::Arc}; use crate::{ common::{CharacterSet, ECIInput, Eci, MinimalECIInput, Result}, @@ -198,7 +198,7 @@ fn encode( shape: SymbolShapeHint, macroId: i32, ) -> Result> { - Ok(encodeMinimally(Rc::new(Input::new( + Ok(encodeMinimally(Arc::new(Input::new( input, priorityCharset, fnc1, @@ -209,7 +209,7 @@ fn encode( .to_vec()) } -fn addEdge(edges: &mut [Vec>>], edge: Rc) -> Result<()> { +fn addEdge(edges: &mut [Vec>>], edge: Arc) -> Result<()> { let vertexIndex = (edge.fromPosition + edge.characterLength) as usize; if edges[vertexIndex][edge.getEndMode()?.ordinal()].is_none() || edges[vertexIndex][edge.getEndMode()?.ordinal()] @@ -231,7 +231,7 @@ fn addEdge(edges: &mut [Vec>>], edge: Rc) -> Result<()> { * is filled with 0 (Shift 1) in this case). */ fn getNumberOfC40Words( - input: Rc, + input: Arc, from: u32, c40: bool, characterLength: &mut [u32], @@ -274,15 +274,15 @@ fn getNumberOfC40Words( } fn addEdges( - input: Rc, - edges: &mut [Vec>>], + input: Arc, + edges: &mut [Vec>>], from: u32, - previous: Option>, + previous: Option>, ) -> Result<()> { if input.isECI(from)? { addEdge( edges, - Rc::new(Edge::new(input, Mode::Ascii, from, 1, previous)?), + Arc::new(Edge::new(input, Mode::Ascii, from, 1, previous)?), )?; return Ok(()); } @@ -298,7 +298,7 @@ fn addEdges( // two digits ASCII encoded addEdge( edges, - Rc::new(Edge::new( + Arc::new(Edge::new( input.clone(), Mode::Ascii, from, @@ -310,7 +310,7 @@ fn addEdges( // one ASCII encoded character or an extended character via Upper Shift addEdge( edges, - Rc::new(Edge::new( + Arc::new(Edge::new( input.clone(), Mode::Ascii, from, @@ -329,7 +329,7 @@ fn addEdges( { addEdge( edges, - Rc::new(Edge::new( + Arc::new(Edge::new( input.clone(), mode, from, @@ -347,7 +347,7 @@ fn addEdges( { addEdge( edges, - Rc::new(Edge::new( + Arc::new(Edge::new( input.clone(), Mode::X12, from, @@ -359,7 +359,7 @@ fn addEdges( addEdge( edges, - Rc::new(Edge::new( + Arc::new(Edge::new( input.clone(), Mode::B256, from, @@ -380,7 +380,7 @@ fn addEdges( { addEdge( edges, - Rc::new(Edge::new( + Arc::new(Edge::new( input.clone(), Mode::Edf, from, @@ -399,13 +399,13 @@ fn addEdges( { addEdge( edges, - Rc::new(Edge::new(input, Mode::Edf, from, 4, previous)?), + Arc::new(Edge::new(input, Mode::Edf, from, 4, previous)?), )?; } Ok(()) } -fn encodeMinimally(input: Rc) -> Result { +fn encodeMinimally(input: Arc) -> Result { // @SuppressWarnings("checkstyle:lineLength") /* The minimal encoding is computed by Dijkstra. The acyclic graph is modeled as follows: * A vertex represents a combination of a position in the input and an encoding mode where position 0 @@ -648,20 +648,20 @@ const SQUARE_CODEWORD_CAPACITIES: [u32; 24] = [ const RECTANGULAR_CODEWORD_CAPACITIES: [u32; 6] = [5, 10, 16, 33, 32, 49]; struct Edge { - input: Rc, + input: Arc, mode: Mode, //the mode at the start of this edge. fromPosition: u32, characterLength: u32, - previous: Option>, + previous: Option>, cachedTotalSize: u32, } impl Edge { fn new( - input: Rc, + input: Arc, mode: Mode, fromPosition: u32, characterLength: u32, - previous: Option>, + previous: Option>, ) -> Result { if fromPosition + characterLength > input.length() as u32 { return Err(Exceptions::FORMAT); @@ -771,7 +771,7 @@ impl Edge { } // does not count beyond 250 - pub fn getB256Size(mode: Mode, previous: Option>) -> u32 { + pub fn getB256Size(mode: Mode, previous: Option>) -> u32 { if mode != Mode::B256 { return 0; } @@ -790,7 +790,7 @@ impl Edge { cnt } - pub fn getPreviousStartMode(previous: Option>) -> Mode { + pub fn getPreviousStartMode(previous: Option>) -> Mode { if let Some(prev) = previous { prev.mode } else { @@ -799,7 +799,7 @@ impl Edge { // if previous.is_none() { Mode::ASCII} else {previous.as_ref().unwrap().mode} } - pub fn getPreviousMode(previous: Option>) -> Result { + pub fn getPreviousMode(previous: Option>) -> Result { if let Some(prev) = previous { prev.getEndMode() } else { @@ -812,7 +812,7 @@ impl Edge { * - Mode is EDIFACT and characterLength is less than 4 or the remaining characters can be encoded in at most 2 * ASCII bytes. * - Mode is C40, TEXT or X12 and the remaining characters can be encoded in at most 1 ASCII byte. - * + * * Returns mode in all other cases. * */ pub fn getEndMode(&self) -> Result { @@ -1270,7 +1270,7 @@ struct RXingResult { bytes: Vec, } impl RXingResult { - pub fn new(solution: Option>) -> Result { + pub fn new(solution: Option>) -> Result { let solution = if let Some(edge) = solution { edge } else { diff --git a/src/lib.rs b/src/lib.rs index b312d081..923c3cc2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,7 +11,7 @@ pub mod qrcode; #[cfg(feature = "client_support")] pub mod client; -use std::{collections::HashMap, rc::Rc}; +use std::{collections::HashMap, sync::Arc}; pub use exceptions::Exceptions; @@ -39,7 +39,7 @@ pub use encode_hints::*; /// Callback which is invoked when a possible result point (significant /// point in the barcode image such as a corner) is found. -pub type PointCallback = Rc; +pub type PointCallback = Arc; /** Temporary type to ease refactoring and keep backwards-compatibility */ pub type RXingResultPointCallback = PointCallback; diff --git a/src/pdf417/decoder/bounding_box.rs b/src/pdf417/decoder/bounding_box.rs index 49cecf3a..0494f66d 100644 --- a/src/pdf417/decoder/bounding_box.rs +++ b/src/pdf417/decoder/bounding_box.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::rc::Rc; +use std::sync::Arc; use crate::{ common::{BitMatrix, Result}, @@ -26,7 +26,7 @@ use crate::{ */ #[derive(Clone)] pub struct BoundingBox { - image: Rc, + image: Arc, topLeft: Point, bottomLeft: Point, topRight: Point, @@ -38,7 +38,7 @@ pub struct BoundingBox { } impl BoundingBox { pub fn new( - image: Rc, + image: Arc, topLeft: Option, bottomLeft: Option, topRight: Option, @@ -85,7 +85,7 @@ impl BoundingBox { }) } - pub fn from_other(boundingBox: Rc) -> BoundingBox { + pub fn from_other(boundingBox: Arc) -> BoundingBox { BoundingBox { image: boundingBox.image.clone(), topLeft: boundingBox.topLeft, diff --git a/src/pdf417/decoder/decoded_bit_stream_parser.rs b/src/pdf417/decoder/decoded_bit_stream_parser.rs index dfff14e8..88f53778 100644 --- a/src/pdf417/decoder/decoded_bit_stream_parser.rs +++ b/src/pdf417/decoder/decoded_bit_stream_parser.rs @@ -16,7 +16,7 @@ */ use num::{self, bigint::ToBigUint, BigUint}; -use std::rc::Rc; +use std::sync::Arc; use crate::{ common::{DecoderRXingResult, ECIStringBuilder, Eci, Result}, @@ -171,7 +171,7 @@ pub fn decode(codewords: &[u32], ecLevel: &str) -> Result { Vec::new(), ecLevel.to_owned(), ); - decoderRXingResult.setOther(Some(Rc::new(resultMetadata))); + decoderRXingResult.setOther(Some(Arc::new(resultMetadata))); Ok(decoderRXingResult) } diff --git a/src/pdf417/decoder/detection_result.rs b/src/pdf417/decoder/detection_result.rs index 7b40bbee..43e0f6d5 100644 --- a/src/pdf417/decoder/detection_result.rs +++ b/src/pdf417/decoder/detection_result.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::{fmt::Display, rc::Rc}; +use std::{fmt::Display, sync::Arc}; use crate::pdf417::pdf_417_common; @@ -31,14 +31,14 @@ const ADJUST_ROW_NUMBER_SKIP: u32 = 2; pub struct DetectionRXingResult { barcodeMetadata: BarcodeMetadata, detectionRXingResultColumns: Vec>>, - boundingBox: Rc, + boundingBox: Arc, barcodeColumnCount: usize, } impl DetectionRXingResult { pub fn new( barcodeMetadata: BarcodeMetadata, - boundingBox: Rc, + boundingBox: Arc, ) -> DetectionRXingResult { let mut columns = Vec::with_capacity(barcodeMetadata.getColumnCount() as usize + 2); for _i in 0..(barcodeMetadata.getColumnCount() as usize + 2) { @@ -601,11 +601,11 @@ impl DetectionRXingResult { self.barcodeMetadata.getErrorCorrectionLevel() } - pub fn setBoundingBox(&mut self, boundingBox: Rc) { + pub fn setBoundingBox(&mut self, boundingBox: Arc) { self.boundingBox = boundingBox; } - pub fn getBoundingBox(&self) -> Rc { + pub fn getBoundingBox(&self) -> Arc { self.boundingBox.clone() } diff --git a/src/pdf417/decoder/detection_result_column.rs b/src/pdf417/decoder/detection_result_column.rs index bdeb0ea8..58add01b 100644 --- a/src/pdf417/decoder/detection_result_column.rs +++ b/src/pdf417/decoder/detection_result_column.rs @@ -14,17 +14,17 @@ * limitations under the License. */ -use std::{fmt::Display, rc::Rc}; +use std::{fmt::Display, sync::Arc}; use super::{BoundingBox, Codeword, DetectionRXingResultRowIndicatorColumn}; const MAX_NEARBY_DISTANCE: u32 = 5; pub trait DetectionRXingResultColumnTrait { - fn new_column(boundingBox: Rc) -> DetectionRXingResultColumn + fn new_column(boundingBox: Arc) -> DetectionRXingResultColumn where Self: Sized; - fn new_with_is_left(boundingBox: Rc, isLeft: bool) -> DetectionRXingResultColumn + fn new_with_is_left(boundingBox: Arc, isLeft: bool) -> DetectionRXingResultColumn where Self: Sized; fn getCodewordNearby(&self, imageRow: u32) -> &Option; @@ -48,7 +48,7 @@ pub struct DetectionRXingResultColumn { } impl DetectionRXingResultColumnTrait for DetectionRXingResultColumn { - fn new_column(boundingBox: Rc) -> DetectionRXingResultColumn { + fn new_column(boundingBox: Arc) -> DetectionRXingResultColumn { DetectionRXingResultColumn { boundingBox: BoundingBox::from_other(boundingBox.clone()), codewords: vec![None; (boundingBox.getMaxY() - boundingBox.getMinY() + 1) as usize], @@ -56,7 +56,7 @@ impl DetectionRXingResultColumnTrait for DetectionRXingResultColumn { } } - fn new_with_is_left(boundingBox: Rc, isLeft: bool) -> DetectionRXingResultColumn { + fn new_with_is_left(boundingBox: Arc, isLeft: bool) -> DetectionRXingResultColumn { DetectionRXingResultColumn { boundingBox: BoundingBox::from_other(boundingBox.clone()), codewords: vec![None; (boundingBox.getMaxY() - boundingBox.getMinY() + 1) as usize], diff --git a/src/pdf417/decoder/ec/error_correction.rs b/src/pdf417/decoder/ec/error_correction.rs index 7c573332..a18503df 100644 --- a/src/pdf417/decoder/ec/error_correction.rs +++ b/src/pdf417/decoder/ec/error_correction.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::rc::Rc; +use std::sync::Arc; use crate::{ common::Result, @@ -26,7 +26,7 @@ use super::ModulusPoly; use once_cell::sync::Lazy; -// static ref PDF417_GF : Rc<&ModulusGF> = Rc::new(&ModulusGF::new(NUMBER_OF_CODEWORDS, 3)); +// static ref PDF417_GF : Arc<&ModulusGF> = Arc::new(&ModulusGF::new(NUMBER_OF_CODEWORDS, 3)); static FLD_INTERIOR: Lazy = Lazy::new(|| ModulusGF::new(NUMBER_OF_CODEWORDS, 3)); /** @@ -64,10 +64,10 @@ pub fn decode(received: &mut [u32], numECCodewords: u32, erasures: &mut [u32]) - return Ok(0); } - let mut knownErrors: Rc = ModulusPoly::getOne(field); + let mut knownErrors: Arc = ModulusPoly::getOne(field); let mut b; let mut term; - let mut kE: Rc; + let mut kE: Arc; if !erasures.is_empty() { for erasure in erasures { // for (int erasure : erasures) { @@ -75,11 +75,11 @@ pub fn decode(received: &mut [u32], numECCodewords: u32, erasures: &mut [u32]) - // Add (1 - bx) term: term = ModulusPoly::new(field, vec![field.subtract(0, b), 1])?; kE = knownErrors.clone(); - knownErrors = kE.multiply(Rc::new(term))?; + knownErrors = kE.multiply(Arc::new(term))?; } } - let syndrome = Rc::new(ModulusPoly::new(field, S)?); + let syndrome = Arc::new(ModulusPoly::new(field, S)?); //syndrome = syndrome.multiply(knownErrors); let sigmaOmega = runEuclideanAlgorithm( @@ -110,11 +110,11 @@ pub fn decode(received: &mut [u32], numECCodewords: u32, erasures: &mut [u32]) - } fn runEuclideanAlgorithm( - a: Rc, - b: Rc, + a: Arc, + b: Arc, R: u32, field: &'static ModulusGF, -) -> Result<[Rc; 2]> { +) -> Result<[Arc; 2]> { // Assume a's degree is >= b's let mut a = a; let mut b = b; @@ -169,7 +169,7 @@ fn runEuclideanAlgorithm( Ok([sigma, omega]) } -fn findErrorLocations(errorLocator: Rc, field: &ModulusGF) -> Result> { +fn findErrorLocations(errorLocator: Arc, field: &ModulusGF) -> Result> { // This is a direct application of Chien's search let numErrors = errorLocator.getDegree(); let mut result = vec![0u32; numErrors as usize]; @@ -190,8 +190,8 @@ fn findErrorLocations(errorLocator: Rc, field: &ModulusGF) -> Resul } fn findErrorMagnitudes( - errorEvaluator: Rc, - errorLocator: Rc, + errorEvaluator: Arc, + errorLocator: Arc, errorLocations: &mut [u32], field: &'static ModulusGF, ) -> Vec { diff --git a/src/pdf417/decoder/ec/modulus_gf.rs b/src/pdf417/decoder/ec/modulus_gf.rs index dd811ff9..63de6d5e 100644 --- a/src/pdf417/decoder/ec/modulus_gf.rs +++ b/src/pdf417/decoder/ec/modulus_gf.rs @@ -29,8 +29,8 @@ use crate::Exceptions; pub struct ModulusGF { expTable: Vec, logTable: Vec, - // zero: Option>>, - // one: Option>>, + // zero: Option>>, + // one: Option>>, modulus: u32, generator: u32, } diff --git a/src/pdf417/decoder/ec/modulus_poly.rs b/src/pdf417/decoder/ec/modulus_poly.rs index 0ee94578..3c8a05a3 100644 --- a/src/pdf417/decoder/ec/modulus_poly.rs +++ b/src/pdf417/decoder/ec/modulus_poly.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::rc::Rc; +use std::sync::Arc; use crate::common::Result; use crate::Exceptions; @@ -28,8 +28,8 @@ use super::ModulusGF; pub struct ModulusPoly { field: &'static ModulusGF, coefficients: Vec, - // zero: Option>, - // one: Option>, + // zero: Option>, + // one: Option>, } impl ModulusPoly { pub fn new(field: &'static ModulusGF, coefficients: Vec) -> Result { @@ -122,7 +122,7 @@ impl ModulusPoly { result } - pub fn add(&self, other: Rc) -> Result> { + pub fn add(&self, other: Arc) -> Result> { if self.field != other.field { return Err(Exceptions::illegal_argument_with( "ModulusPolys do not have same ModulusGF field", @@ -132,7 +132,7 @@ impl ModulusPoly { return Ok(other); } if other.isZero() { - return Ok(Rc::new(self.clone())); + return Ok(Arc::new(self.clone())); } let mut smallerCoefficients = &self.coefficients; @@ -153,22 +153,22 @@ impl ModulusPoly { .add(smallerCoefficients[i - lengthDiff], largerCoefficients[i]); } - Ok(Rc::new(ModulusPoly::new(self.field, sumDiff)?)) + Ok(Arc::new(ModulusPoly::new(self.field, sumDiff)?)) } - pub fn subtract(&self, other: Rc) -> Result> { + pub fn subtract(&self, other: Arc) -> Result> { if self.field != other.field { return Err(Exceptions::illegal_argument_with( "ModulusPolys do not have same ModulusGF field", )); } if other.isZero() { - return Ok(Rc::new(self.clone())); + return Ok(Arc::new(self.clone())); }; self.add(other.negative()) } - pub fn multiply(&self, other: Rc) -> Result> { + pub fn multiply(&self, other: Arc) -> Result> { if !(self.field == other.field) { return Err(Exceptions::illegal_argument_with( "ModulusPolys do not have same ModulusGF field", @@ -194,28 +194,28 @@ impl ModulusPoly { } } - Ok(Rc::new(ModulusPoly::new(self.field, product)?)) + Ok(Arc::new(ModulusPoly::new(self.field, product)?)) } - pub fn negative(&self) -> Rc { + pub fn negative(&self) -> Arc { let size = self.coefficients.len(); let mut negativeCoefficients = vec![0u32; size]; for (i, neg_coef) in negativeCoefficients.iter_mut().enumerate().take(size) { // for (int i = 0; i < size; i++) { *neg_coef = self.field.subtract(0, self.coefficients[i]); } - Rc::new( + Arc::new( ModulusPoly::new(self.field, negativeCoefficients) .expect("should always generate with known goods"), ) } - pub fn multiplyByScaler(&self, scalar: u32) -> Rc { + pub fn multiplyByScaler(&self, scalar: u32) -> Arc { if scalar == 0 { return Self::getZero(self.field); } if scalar == 1 { - return Rc::new(self.clone()); + return Arc::new(self.clone()); } let size = self.coefficients.len(); let mut product = vec![0u32; size]; @@ -224,12 +224,12 @@ impl ModulusPoly { *prod = self.field.multiply(self.coefficients[i], scalar); } - Rc::new( + Arc::new( ModulusPoly::new(self.field, product).expect("should always generate with known goods"), ) } - pub fn multiplyByMonomial(&self, degree: usize, coefficient: u32) -> Rc { + pub fn multiplyByMonomial(&self, degree: usize, coefficient: u32) -> Arc { if coefficient == 0 { return Self::getZero(self.field); } @@ -240,24 +240,24 @@ impl ModulusPoly { *prod = self.field.multiply(self.coefficients[i], coefficient); } - Rc::new( + Arc::new( ModulusPoly::new(self.field, product).expect("should always generate with known goods"), ) } - pub fn getZero(field: &'static ModulusGF) -> Rc { - Rc::new(ModulusPoly::new(field, vec![0]).expect("should always generate with known goods")) + pub fn getZero(field: &'static ModulusGF) -> Arc { + Arc::new(ModulusPoly::new(field, vec![0]).expect("should always generate with known goods")) } - pub fn getOne(field: &'static ModulusGF) -> Rc { - Rc::new(ModulusPoly::new(field, vec![1]).expect("should always generate with known goods")) + pub fn getOne(field: &'static ModulusGF) -> Arc { + Arc::new(ModulusPoly::new(field, vec![1]).expect("should always generate with known goods")) } pub fn buildMonomial( field: &'static ModulusGF, degree: usize, coefficient: u32, - ) -> Rc { + ) -> Arc { // if degree < 0 { // throw new IllegalArgumentException(); // } @@ -266,7 +266,7 @@ impl ModulusPoly { } let mut coefficients = vec![0_u32; degree + 1]; coefficients[0] = coefficient; - Rc::new( + Arc::new( ModulusPoly::new(field, coefficients).expect("should always generate with known goods"), ) } diff --git a/src/pdf417/decoder/pdf_417_scanning_decoder.rs b/src/pdf417/decoder/pdf_417_scanning_decoder.rs index f00d5188..a4b409ba 100644 --- a/src/pdf417/decoder/pdf_417_scanning_decoder.rs +++ b/src/pdf417/decoder/pdf_417_scanning_decoder.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::rc::Rc; +use std::sync::Arc; use crate::{ common::{BitMatrix, DecoderRXingResult, Result}, @@ -53,8 +53,8 @@ pub fn decode( ) -> Result { let mut minCodewordWidth = minCodewordWidth; let mut maxCodewordWidth = maxCodewordWidth; - let mut boundingBox = Rc::new(BoundingBox::new( - Rc::new(image.clone()), + let mut boundingBox = Arc::new(BoundingBox::new( + Arc::new(image.clone()), image_top_left, imageBottomLeft, image_top_right, @@ -188,7 +188,7 @@ fn merge<'a, T: DetectionRXingResultRowIndicatorColumn>( if barcodeMetadata.is_none() { return Ok(None); } - let boundingBox = Rc::new(BoundingBox::merge( + let boundingBox = Arc::new(BoundingBox::merge( adjustBoundingBox(leftRowIndicatorColumn)?, adjustBoundingBox(rightRowIndicatorColumn)?, )?); @@ -357,7 +357,7 @@ fn getBarcodeMetadata( fn getRowIndicatorColumn<'a>( image: &BitMatrix, - boundingBox: Rc, + boundingBox: Arc, startPoint: Point, leftToRight: bool, minCodewordWidth: u32, diff --git a/src/qrcode/decoder/qrcode_decoder.rs b/src/qrcode/decoder/qrcode_decoder.rs index e90b3506..70adb9d0 100644 --- a/src/qrcode/decoder/qrcode_decoder.rs +++ b/src/qrcode/decoder/qrcode_decoder.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::{collections::HashMap, rc::Rc}; +use std::{collections::HashMap, sync::Arc}; /** *

The main class which implements QR Code decoding -- as opposed to locating and extracting @@ -117,7 +117,7 @@ pub fn decode_bitmatrix_with_hints( let mut result = decode_bitmatrix_parser_with_hints(&mut parser, hints)?; // Success! Notify the caller that the code was mirrored. - result.setOther(Some(Rc::new(QRCodeDecoderMetaData::new(true)))); + result.setOther(Some(Arc::new(QRCodeDecoderMetaData::new(true)))); Ok(result) }; diff --git a/src/qrcode/encoder/minimal_encoder.rs b/src/qrcode/encoder/minimal_encoder.rs index fdb07a4b..3bfa0ede 100644 --- a/src/qrcode/encoder/minimal_encoder.rs +++ b/src/qrcode/encoder/minimal_encoder.rs @@ -14,7 +14,7 @@ * limitations under the License. */ -use std::{fmt, rc::Rc}; +use std::{fmt, sync::Arc}; use crate::{ common::{BitArray, BitFieldBaseType, CharacterSet, ECIEncoderSet, Result}, @@ -253,9 +253,9 @@ impl MinimalEncoder { pub fn addEdge( &self, - edges: &mut [Vec>>>], + edges: &mut [Vec>>>], position: usize, - edge: Option>, + edge: Option>, ) -> Result<()> { let vertexIndex = position + edge.as_ref().ok_or(Exceptions::FORMAT)?.characterLength as usize; @@ -280,9 +280,9 @@ impl MinimalEncoder { pub fn addEdges( &self, version: VersionRef, - edges: &mut [Vec>>>], + edges: &mut [Vec>>>], from: usize, - previous: Option>, + previous: Option>, ) -> Result<()> { let mut start = 0; let mut end = self.encoders.len(); @@ -314,7 +314,7 @@ impl MinimalEncoder { self.addEdge( edges, from, - Some(Rc::new( + Some(Arc::new( Edge::new( Mode::BYTE, from, @@ -338,7 +338,7 @@ impl MinimalEncoder { self.addEdge( edges, from, - Some(Rc::new( + Some(Arc::new( Edge::new( Mode::KANJI, from, @@ -364,7 +364,7 @@ impl MinimalEncoder { self.addEdge( edges, from, - Some(Rc::new( + Some(Arc::new( Edge::new( Mode::ALPHANUMERIC, from, @@ -400,7 +400,7 @@ impl MinimalEncoder { self.addEdge( edges, from, - Some(Rc::new( + Some(Arc::new( Edge::new( Mode::NUMERIC, from, @@ -616,7 +616,7 @@ pub struct Edge { fromPosition: usize, charsetEncoderIndex: usize, characterLength: u32, - previous: Option>, + previous: Option>, cachedTotalSize: u32, _encoders: ECIEncoderSet, _stringToEncode: Vec, @@ -628,7 +628,7 @@ impl Edge { fromPosition: usize, charsetEncoderIndex: usize, characterLength: u32, - previous: Option>, + previous: Option>, version: VersionRef, encoders: ECIEncoderSet, stringToEncode: Vec, @@ -701,7 +701,7 @@ pub struct RXingResultList { impl RXingResultList { pub fn new( version: VersionRef, - solution: Rc, + solution: Arc, isGS1: bool, ecLevel: &ErrorCorrectionLevel, encoders: ECIEncoderSet, diff --git a/src/rxing_result_metadata.rs b/src/rxing_result_metadata.rs index 630533db..c41eca6e 100644 --- a/src/rxing_result_metadata.rs +++ b/src/rxing_result_metadata.rs @@ -16,7 +16,7 @@ //package com.google.zxing; -use std::rc::Rc; +use std::sync::Arc; use crate::pdf417::PDF417RXingResultMetadata; @@ -216,7 +216,7 @@ pub enum RXingResultMetadataValue { /** * PDF417-specific metadata */ - Pdf417ExtraMetadata(Rc), + Pdf417ExtraMetadata(Arc), /** * If the code format supports structured append and the current scanned code is part of one then the diff --git a/tests/common/abstract_black_box_test_case.rs b/tests/common/abstract_black_box_test_case.rs index f89b9ab4..c01cd692 100644 --- a/tests/common/abstract_black_box_test_case.rs +++ b/tests/common/abstract_black_box_test_case.rs @@ -21,7 +21,7 @@ use std::{ fs::{read_dir, read_to_string, File}, io::Read, path::{Path, PathBuf}, - rc::Rc, + sync::Arc, }; use encoding::Encoding; @@ -221,7 +221,7 @@ impl AbstractBlackBoxTestCase { RXingResultMetadataValue::UpcEanExtension(v) } RXingResultMetadataType::PDF417_EXTRA_METADATA => { - RXingResultMetadataValue::Pdf417ExtraMetadata(Rc::new( + RXingResultMetadataValue::Pdf417ExtraMetadata(Arc::new( PDF417RXingResultMetadata::default(), )) } diff --git a/tests/common/multiimage_span.rs b/tests/common/multiimage_span.rs index 17f5cf99..d6d06179 100644 --- a/tests/common/multiimage_span.rs +++ b/tests/common/multiimage_span.rs @@ -20,7 +20,7 @@ use std::{ fs::{read_dir, read_to_string, File}, io::Read, path::{Path, PathBuf}, - rc::Rc, + sync::Arc, }; use rxing::{ @@ -377,7 +377,7 @@ impl MultiImageSpanAbstractBlackBoxTestCase { - RXingResultMetadataValue::Pdf417ExtraMetadata(Rc::new( + RXingResultMetadataValue::Pdf417ExtraMetadata(Arc::new( PDF417RXingResultMetadata::default(), )) } @@ -771,7 +771,7 @@ impl MultiImageSpanAbstractBlackBoxTestCase Option> { + fn get_meta(result: &RXingResult) -> Option> { if let Some(RXingResultMetadataValue::Pdf417ExtraMetadata(mtd)) = result .getRXingResultMetadata() .get(&RXingResultMetadataType::PDF417_EXTRA_METADATA)