mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-27 21:02:35 +00:00
Use thiserror for error handling with less boilerplate
This commit is contained in:
@@ -60,7 +60,7 @@ impl Writer for PDF417Writer {
|
||||
hints: &crate::EncodingHintDictionary,
|
||||
) -> Result<crate::common::BitMatrix> {
|
||||
if format != &BarcodeFormat::PDF_417 {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Can only encode PDF_417, but got {format}"
|
||||
)));
|
||||
}
|
||||
@@ -150,7 +150,7 @@ impl PDF417Writer {
|
||||
let mut originalScale = encoder
|
||||
.getBarcodeMatrix()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::illegalState)?
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
.getScaledMatrix(1, aspectRatio);
|
||||
let mut rotated = false;
|
||||
if (height > width) != (originalScale[0].len() < originalScale.len()) {
|
||||
@@ -166,16 +166,16 @@ impl PDF417Writer {
|
||||
let mut scaledMatrix = encoder
|
||||
.getBarcodeMatrix()
|
||||
.as_ref()
|
||||
.ok_or(Exceptions::illegalState)?
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
.getScaledMatrix(scale, scale * aspectRatio);
|
||||
if rotated {
|
||||
scaledMatrix = Self::rotateArray(&scaledMatrix);
|
||||
}
|
||||
return Self::bitMatrixFromBitArray(&scaledMatrix, margin)
|
||||
.ok_or(Exceptions::illegalState);
|
||||
.ok_or(Exceptions::ILLEGAL_STATE);
|
||||
}
|
||||
|
||||
Self::bitMatrixFromBitArray(&originalScale, margin).ok_or(Exceptions::illegalState)
|
||||
Self::bitMatrixFromBitArray(&originalScale, margin).ok_or(Exceptions::ILLEGAL_STATE)
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user