mirror of
https://github.com/starovoid/rxing.git
synced 2026-07-26 12:22:34 +00:00
Use thiserror for error handling with less boilerplate
This commit is contained in:
@@ -222,14 +222,14 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
||||
|
||||
if forceC40 {
|
||||
c40Encoder.encodeMaximalC40(&mut context)?;
|
||||
encodingMode = context.getNewEncoding().ok_or(Exceptions::illegalState)?;
|
||||
encodingMode = context.getNewEncoding().ok_or(Exceptions::ILLEGAL_STATE)?;
|
||||
context.resetEncoderSignal();
|
||||
}
|
||||
|
||||
while context.hasMoreCharacters() {
|
||||
encoders[encodingMode].encode(&mut context)?;
|
||||
if context.getNewEncoding().is_some() {
|
||||
encodingMode = context.getNewEncoding().ok_or(Exceptions::illegalState)?;
|
||||
encodingMode = context.getNewEncoding().ok_or(Exceptions::ILLEGAL_STATE)?;
|
||||
context.resetEncoderSignal();
|
||||
}
|
||||
}
|
||||
@@ -237,7 +237,7 @@ pub fn encodeHighLevelWithDimensionForceC40WithSymbolInfoLookup(
|
||||
context.updateSymbolInfo();
|
||||
let capacity = context
|
||||
.getSymbolInfo()
|
||||
.ok_or(Exceptions::illegalState)?
|
||||
.ok_or(Exceptions::ILLEGAL_STATE)?
|
||||
.getDataCapacity();
|
||||
if len < capacity as usize
|
||||
&& encodingMode != ASCII_ENCODATION
|
||||
@@ -608,7 +608,7 @@ pub fn determineConsecutiveDigitCount(msg: &str, startpos: u32) -> u32 {
|
||||
pub fn illegalCharacter(c: char) -> Result<()> {
|
||||
// let hex = Integer.toHexString(c);
|
||||
// hex = "0000".substring(0, 4 - hex.length()) + hex;
|
||||
Err(Exceptions::illegalArgumentWith(format!(
|
||||
Err(Exceptions::illegal_argument_with(format!(
|
||||
"Illegal character: {c} (0x{c})"
|
||||
)))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user