mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 04:12:34 +00:00
Use thiserror for error handling with less boilerplate
This commit is contained in:
@@ -89,7 +89,7 @@ pub fn decode(bytes: &[u8], mode: u8) -> Result<DecoderRXingResult> {
|
||||
let pc = getPostCode2(bytes);
|
||||
let ps2Length = getPostCode2Length(bytes) as usize;
|
||||
if ps2Length > 10 {
|
||||
return Err(Exceptions::format);
|
||||
return Err(Exceptions::FORMAT);
|
||||
}
|
||||
// NumberFormat df = new DecimalFormat("0000000000".substring(0, ps2Length));
|
||||
// postcode = df.format(pc);
|
||||
|
||||
@@ -70,7 +70,7 @@ pub fn decode_with_hints(
|
||||
correctErrors(&mut codewords, 20, 68, 56, ODD)?;
|
||||
datawords = vec![0u8; 78];
|
||||
}
|
||||
_ => return Err(Exceptions::notFound),
|
||||
_ => return Err(Exceptions::NOT_FOUND),
|
||||
}
|
||||
|
||||
datawords[0..10].clone_from_slice(&codewords[0..10]);
|
||||
|
||||
@@ -316,7 +316,7 @@ impl Circle<'_> {
|
||||
pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionResult> {
|
||||
// find concentric circles
|
||||
let Some( mut circles) = find_concentric_circles(image) else {
|
||||
return Err(Exceptions::notFound);
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
};
|
||||
|
||||
// we should have an idea where the center is at this point,
|
||||
@@ -339,7 +339,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
||||
if try_harder {
|
||||
continue;
|
||||
}else {
|
||||
return Err(Exceptions::notFound)
|
||||
return Err(Exceptions::NOT_FOUND)
|
||||
}
|
||||
};
|
||||
let grid_sampler = DefaultGridSampler::default();
|
||||
@@ -376,7 +376,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
||||
if try_harder {
|
||||
continue;
|
||||
}else {
|
||||
return Err(Exceptions::notFound)
|
||||
return Err(Exceptions::NOT_FOUND)
|
||||
}
|
||||
};
|
||||
return Ok(MaxicodeDetectionResult {
|
||||
@@ -390,7 +390,7 @@ pub fn detect(image: &BitMatrix, try_harder: bool) -> Result<MaxicodeDetectionRe
|
||||
});
|
||||
}
|
||||
|
||||
Err(Exceptions::notFound)
|
||||
Err(Exceptions::NOT_FOUND)
|
||||
}
|
||||
|
||||
/// Locate concentric circles.
|
||||
@@ -729,7 +729,7 @@ fn box_symbol(image: &BitMatrix, circle: &mut Circle) -> Result<([(f32, f32); 4]
|
||||
#[cfg(feature = "experimental_features")]
|
||||
if is_ellipse {
|
||||
// we don't deal with ellipses yet
|
||||
return Err(Exceptions::notFound);
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
}
|
||||
|
||||
let mut final_rotation = 0.0;
|
||||
@@ -1049,7 +1049,7 @@ fn compare_circle(a: &Circle, b: &Circle) -> std::cmp::Ordering {
|
||||
pub fn read_bits(image: &BitMatrix) -> Result<BitMatrix> {
|
||||
let enclosingRectangle = image
|
||||
.getEnclosingRectangle()
|
||||
.ok_or(Exceptions::NotFoundException(None))?;
|
||||
.ok_or(Exceptions::NOT_FOUND)?;
|
||||
|
||||
let left = enclosingRectangle[0];
|
||||
let top = enclosingRectangle[1];
|
||||
|
||||
@@ -123,10 +123,10 @@ impl MaxiCodeReader {
|
||||
fn extractPureBits(image: &BitMatrix) -> Result<BitMatrix> {
|
||||
let enclosingRectangleOption = image.getEnclosingRectangle();
|
||||
if enclosingRectangleOption.is_none() {
|
||||
return Err(Exceptions::notFound);
|
||||
return Err(Exceptions::NOT_FOUND);
|
||||
}
|
||||
|
||||
let enclosingRectangle = enclosingRectangleOption.ok_or(Exceptions::notFound)?;
|
||||
let enclosingRectangle = enclosingRectangleOption.ok_or(Exceptions::NOT_FOUND)?;
|
||||
|
||||
let left = enclosingRectangle[0];
|
||||
let top = enclosingRectangle[1];
|
||||
|
||||
Reference in New Issue
Block a user