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

@@ -169,7 +169,7 @@ impl BitArray {
pub fn setRange(&mut self, start: usize, end: usize) -> Result<()> {
let mut end = end;
if end < start || end > self.size {
return Err(Exceptions::illegalArgument);
return Err(Exceptions::ILLEGAL_ARGUMENT);
}
if end == start {
return Ok(());
@@ -212,7 +212,7 @@ impl BitArray {
pub fn isRange(&self, start: usize, end: usize, value: bool) -> Result<bool> {
let mut end = end;
if end < start || end > self.size {
return Err(Exceptions::illegalArgument);
return Err(Exceptions::ILLEGAL_ARGUMENT);
}
if end == start {
return Ok(true); // empty range matches
@@ -254,7 +254,7 @@ impl BitArray {
*/
pub fn appendBits(&mut self, value: u32, num_bits: usize) -> Result<()> {
if num_bits > 32 {
return Err(Exceptions::illegalArgumentWith(
return Err(Exceptions::illegal_argument_with(
"num bits must be between 0 and 32",
));
}
@@ -287,7 +287,7 @@ impl BitArray {
pub fn xor(&mut self, other: &BitArray) -> Result<()> {
if self.size != other.size {
return Err(Exceptions::illegalArgumentWith("Sizes don't match"));
return Err(Exceptions::illegal_argument_with("Sizes don't match"));
}
for i in 0..self.bits.len() {
//for (int i = 0; i < bits.length; i++) {