change NEEDS_RESULT_CALLBACK to accept closures

This resolves issue #2.
This is a breaking change, and should necessitate moving to v0.3.0

FIXES: #2
This commit is contained in:
Henry Schimke
2023-02-03 14:31:17 -06:00
parent 292e79ae79
commit e3793c8385
3 changed files with 6 additions and 6 deletions

View File

@@ -8,7 +8,7 @@ mod exceptions;
pub mod maxicode; pub mod maxicode;
pub mod qrcode; pub mod qrcode;
use std::collections::HashMap; use std::{collections::HashMap, rc::Rc};
pub use exceptions::Exceptions; pub use exceptions::Exceptions;
@@ -40,7 +40,7 @@ pub use encode_hints::*;
* *
* @see DecodeHintType#NEED_RESULT_POINT_CALLBACK * @see DecodeHintType#NEED_RESULT_POINT_CALLBACK
*/ */
pub type RXingResultPointCallback = fn(&dyn ResultPoint); pub type RXingResultPointCallback = Rc<dyn Fn(&dyn ResultPoint)>;
mod decode_hints; mod decode_hints;
pub use decode_hints::*; pub use decode_hints::*;

View File

@@ -45,7 +45,7 @@ impl<'a> MultiDetector<'_> {
let resultPointCallback = if let Some(DecodeHintValue::NeedResultPointCallback(cb)) = let resultPointCallback = if let Some(DecodeHintValue::NeedResultPointCallback(cb)) =
hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK) hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK)
{ {
Some(*cb) Some(cb.clone())
} else { } else {
None None
}; };

View File

@@ -84,7 +84,7 @@ impl<'a> Detector<'_> {
hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK) hints.get(&DecodeHintType::NEED_RESULT_POINT_CALLBACK)
{ {
// if let DecodeHintValue::NeedResultPointCallback(cb) = nrpc { // if let DecodeHintValue::NeedResultPointCallback(cb) = nrpc {
Some(*cb) Some(cb.clone())
// } else { // } else {
// None // None
// } // }
@@ -97,7 +97,7 @@ impl<'a> Detector<'_> {
// (RXingResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK); // (RXingResultPointCallback) hints.get(DecodeHintType.NEED_RESULT_POINT_CALLBACK);
let mut finder = let mut finder =
FinderPatternFinder::with_callback(self.image.clone(), self.resultPointCallback); FinderPatternFinder::with_callback(self.image.clone(), self.resultPointCallback.clone());
let info = finder.find(hints)?; let info = finder.find(hints)?;
self.processFinderPatternInfo(info) self.processFinderPatternInfo(info)
@@ -479,7 +479,7 @@ impl<'a> Detector<'_> {
alignmentAreaRightX - alignmentAreaLeftX, alignmentAreaRightX - alignmentAreaLeftX,
alignmentAreaBottomY - alignmentAreaTopY, alignmentAreaBottomY - alignmentAreaTopY,
overallEstModuleSize, overallEstModuleSize,
self.resultPointCallback, self.resultPointCallback.clone(),
); );
alignmentFinder.find() alignmentFinder.find()
} }