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:
@@ -68,10 +68,10 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn charAt(&self, index: usize) -> Result<char> {
|
||||
if index >= self.length() {
|
||||
return Err(Exceptions::indexOutOfBoundsWith(index.to_string()));
|
||||
return Err(Exceptions::index_out_of_bounds_with(index.to_string()));
|
||||
}
|
||||
if self.isECI(index as u32)? {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"value at {index} is not a character but an ECI"
|
||||
)));
|
||||
}
|
||||
@@ -104,13 +104,13 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn subSequence(&self, start: usize, end: usize) -> Result<Vec<char>> {
|
||||
if start > end || end > self.length() {
|
||||
return Err(Exceptions::indexOutOfBounds);
|
||||
return Err(Exceptions::INDEX_OUT_OF_BOUNDS);
|
||||
}
|
||||
let mut result = String::new();
|
||||
for i in start..end {
|
||||
// for (int i = start; i < end; i++) {
|
||||
if self.isECI(i as u32)? {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"value at {i} is not a character but an ECI"
|
||||
)));
|
||||
}
|
||||
@@ -132,7 +132,7 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn isECI(&self, index: u32) -> Result<bool> {
|
||||
if index >= self.length() as u32 {
|
||||
return Err(Exceptions::indexOutOfBounds);
|
||||
return Err(Exceptions::INDEX_OUT_OF_BOUNDS);
|
||||
}
|
||||
Ok(self.bytes[index as usize] > 255) // && self.bytes[index as usize] <= u16::MAX)
|
||||
}
|
||||
@@ -157,10 +157,10 @@ impl ECIInput for MinimalECIInput {
|
||||
*/
|
||||
fn getECIValue(&self, index: usize) -> Result<i32> {
|
||||
if index >= self.length() {
|
||||
return Err(Exceptions::indexOutOfBounds);
|
||||
return Err(Exceptions::INDEX_OUT_OF_BOUNDS);
|
||||
}
|
||||
if !self.isECI(index as u32)? {
|
||||
return Err(Exceptions::illegalArgumentWith(format!(
|
||||
return Err(Exceptions::illegal_argument_with(format!(
|
||||
"value at {index} is not an ECI but a character"
|
||||
)));
|
||||
}
|
||||
@@ -249,7 +249,7 @@ impl MinimalECIInput {
|
||||
*/
|
||||
pub fn isFNC1(&self, index: usize) -> Result<bool> {
|
||||
if index >= self.length() {
|
||||
return Err(Exceptions::indexOutOfBounds);
|
||||
return Err(Exceptions::INDEX_OUT_OF_BOUNDS);
|
||||
}
|
||||
Ok(self.bytes[index] == 1000)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user