Use thiserror for error handling with less boilerplate

This commit is contained in:
Steve Cook
2023-02-20 09:41:28 -05:00
parent 01e4f4a126
commit f8b29f37db
135 changed files with 868 additions and 905 deletions

View File

@@ -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)
}
/**