Use new inclusive range syntax

This commit is contained in:
Elichai Turkel 2020-09-14 17:51:16 +03:00
parent ad0064db14
commit efe1a55819
No known key found for this signature in database
GPG Key ID: 9383CDE9E8E66A7F
11 changed files with 35 additions and 35 deletions

View File

@ -31,9 +31,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -36,9 +36,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -53,9 +53,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -31,9 +31,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -40,9 +40,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -70,9 +70,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -52,9 +52,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -67,9 +67,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -88,9 +88,9 @@ mod tests {
for (idx, c) in hex.as_bytes().iter().enumerate() { for (idx, c) in hex.as_bytes().iter().enumerate() {
b <<= 4; b <<= 4;
match *c { match *c {
b'A'...b'F' => b |= c - b'A' + 10, b'A'..=b'F' => b |= c - b'A' + 10,
b'a'...b'f' => b |= c - b'a' + 10, b'a'..=b'f' => b |= c - b'a' + 10,
b'0'...b'9' => b |= c - b'0', b'0'..=b'9' => b |= c - b'0',
_ => panic!("Bad hex"), _ => panic!("Bad hex"),
} }
if (idx & 1) == 1 { if (idx & 1) == 1 {

View File

@ -376,14 +376,14 @@ impl_int_encodable!(i64, read_i64, emit_i64);
impl VarInt { impl VarInt {
/// Gets the length of this VarInt when encoded. /// Gets the length of this VarInt when encoded.
/// Returns 1 for 0...0xFC, 3 for 0xFD...(2^16-1), 5 for 0x10000...(2^32-1), /// Returns 1 for 0..=0xFC, 3 for 0xFD..=(2^16-1), 5 for 0x10000..=(2^32-1),
/// and 9 otherwise. /// and 9 otherwise.
#[inline] #[inline]
pub fn len(&self) -> usize { pub fn len(&self) -> usize {
match self.0 { match self.0 {
0...0xFC => { 1 } 0..=0xFC => { 1 }
0xFD...0xFFFF => { 3 } 0xFD..=0xFFFF => { 3 }
0x10000...0xFFFFFFFF => { 5 } 0x10000..=0xFFFFFFFF => { 5 }
_ => { 9 } _ => { 9 }
} }
} }
@ -393,16 +393,16 @@ impl Encodable for VarInt {
#[inline] #[inline]
fn consensus_encode<S: io::Write>(&self, mut s: S) -> Result<usize, Error> { fn consensus_encode<S: io::Write>(&self, mut s: S) -> Result<usize, Error> {
match self.0 { match self.0 {
0...0xFC => { 0..=0xFC => {
(self.0 as u8).consensus_encode(s)?; (self.0 as u8).consensus_encode(s)?;
Ok(1) Ok(1)
}, },
0xFD...0xFFFF => { 0xFD..=0xFFFF => {
s.emit_u8(0xFD)?; s.emit_u8(0xFD)?;
(self.0 as u16).consensus_encode(s)?; (self.0 as u16).consensus_encode(s)?;
Ok(3) Ok(3)
}, },
0x10000...0xFFFFFFFF => { 0x10000..=0xFFFFFFFF => {
s.emit_u8(0xFE)?; s.emit_u8(0xFE)?;
(self.0 as u32).consensus_encode(s)?; (self.0 as u32).consensus_encode(s)?;
Ok(5) Ok(5)

View File

@ -172,7 +172,7 @@ fn parse_signed_to_satoshi(
let mut value: u64 = 0; // as satoshis let mut value: u64 = 0; // as satoshis
for c in s.chars() { for c in s.chars() {
match c { match c {
'0'...'9' => { '0'..='9' => {
// Do `value = 10 * value + digit`, catching overflows. // Do `value = 10 * value + digit`, catching overflows.
match 10_u64.checked_mul(value) { match 10_u64.checked_mul(value) {
None => return Err(ParseAmountError::TooBig), None => return Err(ParseAmountError::TooBig),