Skip to content

Commit c009837

Browse files
committed
clippy: fix single_match_else lint
Just style, and apologies for the annoying-to-review diff that moves logic around. But the result is more consistent and (I think) better.
1 parent 64d6853 commit c009837

File tree

2 files changed

+23
-22
lines changed

2 files changed

+23
-22
lines changed

src/address.rs

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -494,19 +494,11 @@ impl Address {
494494
// When blinded, the structure is:
495495
// <1: blinding prefix> <1: regular prefix> <33: blinding pubkey> <20: hash160>
496496

497-
let (blinded, prefix) = match data[0] == params.blinded_prefix {
498-
true => {
499-
if data.len() != 55 {
500-
return Err(AddressError::InvalidLength(data.len()));
501-
}
502-
(true, data[1])
503-
}
504-
false => {
505-
if data.len() != 21 {
506-
return Err(AddressError::InvalidLength(data.len()));
507-
}
508-
(false, data[0])
509-
}
497+
let blinded = data[0] == params.blinded_prefix;
498+
let prefix = match (blinded, data.len()) {
499+
(true, 55) => data[1],
500+
(false, 21) => data[0],
501+
(_, len) => return Err(AddressError::InvalidLength(len)),
510502
};
511503

512504
let (blinding_pubkey, payload_data) = match blinded {

src/script.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -485,29 +485,38 @@ impl Script {
485485
f.write_str("<unexpected end>")?;
486486
break;
487487
}
488-
match read_uint(&self.0[index..], 1) {
489-
Ok(n) => { index += 1; n }
490-
Err(_) => { f.write_str("<bad length>")?; break; }
488+
if let Ok(n) =read_uint(&self.0[index..], 1) {
489+
index += 1;
490+
n
491+
} else {
492+
f.write_str("<bad length>")?;
493+
break;
491494
}
492495
}
493496
opcodes::all::OP_PUSHDATA2 => {
494497
if self.0.len() < index + 2 {
495498
f.write_str("<unexpected end>")?;
496499
break;
497500
}
498-
match read_uint(&self.0[index..], 2) {
499-
Ok(n) => { index += 2; n }
500-
Err(_) => { f.write_str("<bad length>")?; break; }
501+
if let Ok(n) = read_uint(&self.0[index..], 2) {
502+
index += 2;
503+
n
504+
} else {
505+
f.write_str("<bad length>")?;
506+
break;
501507
}
502508
}
503509
opcodes::all::OP_PUSHDATA4 => {
504510
if self.0.len() < index + 4 {
505511
f.write_str("<unexpected end>")?;
506512
break;
507513
}
508-
match read_uint(&self.0[index..], 4) {
509-
Ok(n) => { index += 4; n }
510-
Err(_) => { f.write_str("<bad length>")?; break; }
514+
if let Ok(n) = read_uint(&self.0[index..], 4) {
515+
index += 4;
516+
n
517+
} else {
518+
f.write_str("<bad length>")?;
519+
break;
511520
}
512521
}
513522
_ => 0

0 commit comments

Comments
 (0)