Use new inclusive range syntax
This commit is contained in:
parent
ad0064db14
commit
efe1a55819
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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 {
|
||||||
|
|
|
@ -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)
|
||||||
|
|
|
@ -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),
|
||||||
|
|
Loading…
Reference in New Issue