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:
@@ -33,12 +33,12 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
||||
fn encode_oned(&self, contents: &str) -> Result<Vec<bool>> {
|
||||
let length = contents.chars().count();
|
||||
if length % 2 != 0 {
|
||||
return Err(Exceptions::illegalArgumentWith(
|
||||
return Err(Exceptions::illegal_argument_with(
|
||||
"The length of the input should be even",
|
||||
));
|
||||
}
|
||||
if length > 80 {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"Requested contents should be less than 80 digits long, but got {length}"
|
||||
)));
|
||||
}
|
||||
@@ -52,15 +52,15 @@ impl OneDimensionalCodeWriter for ITFWriter {
|
||||
let one = contents
|
||||
.chars()
|
||||
.nth(i)
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::parse)? as usize;
|
||||
.ok_or(Exceptions::PARSE)? as usize;
|
||||
let two = contents
|
||||
.chars()
|
||||
.nth(i + 1)
|
||||
.ok_or(Exceptions::indexOutOfBounds)?
|
||||
.ok_or(Exceptions::INDEX_OUT_OF_BOUNDS)?
|
||||
.to_digit(10)
|
||||
.ok_or(Exceptions::parse)? as usize;
|
||||
.ok_or(Exceptions::PARSE)? as usize;
|
||||
let mut encoding = [0; 10];
|
||||
for j in 0..5 {
|
||||
encoding[2 * j] = PATTERNS[one][j];
|
||||
|
||||
Reference in New Issue
Block a user