Skip to content

Commit 90f6ce4

Browse files
author
Henrik Gustafsson
committed
Fix clippy::precedence lint in CqlTimeuuid changed in clippy 0.1.85
Introduced by rust-lang/rust-clippy#13743
1 parent ff7bf49 commit 90f6ce4

File tree

1 file changed

+56
-16
lines changed

1 file changed

+56
-16
lines changed

scylla-cql/src/value.rs

Lines changed: 56 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,23 @@ impl CqlTimeuuid {
102102
// 4 bytes 2 bytes 2 bytes
103103
// time_low - time_mid - time_hi_and_version
104104
let bytes = self.0.as_bytes();
105-
((bytes[6] & 0x0F) as u64) << 56
106-
| (bytes[7] as u64) << 48
107-
| (bytes[4] as u64) << 40
108-
| (bytes[5] as u64) << 32
109-
| (bytes[0] as u64) << 24
110-
| (bytes[1] as u64) << 16
111-
| (bytes[2] as u64) << 8
112-
| (bytes[3] as u64)
105+
u64::from_be_bytes([
106+
bytes[6] & 0x0f,
107+
bytes[7],
108+
bytes[4],
109+
bytes[5],
110+
bytes[0],
111+
bytes[1],
112+
bytes[2],
113+
bytes[3],
114+
])
113115
}
114116

115117
fn lsb(&self) -> u64 {
116118
let bytes = self.0.as_bytes();
117-
(bytes[8] as u64) << 56
118-
| (bytes[9] as u64) << 48
119-
| (bytes[10] as u64) << 40
120-
| (bytes[11] as u64) << 32
121-
| (bytes[12] as u64) << 24
122-
| (bytes[13] as u64) << 16
123-
| (bytes[14] as u64) << 8
124-
| (bytes[15] as u64)
119+
u64::from_be_bytes([
120+
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15],
121+
])
125122
}
126123

127124
fn lsb_signed(&self) -> u64 {
@@ -1249,3 +1246,46 @@ pub fn deser_cql_value(
12491246
pub struct Row {
12501247
pub columns: Vec<Option<CqlValue>>,
12511248
}
1249+
1250+
#[cfg(test)]
1251+
mod tests {
1252+
use super::*;
1253+
1254+
#[test]
1255+
fn test_cql_time_uuid_msb_reorders_bytes() {
1256+
let uuid = Uuid::from_slice(&[
1257+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
1258+
0x0e, 0x0f,
1259+
])
1260+
.unwrap();
1261+
let uuid = CqlTimeuuid(uuid);
1262+
1263+
assert_eq!(0x0607040500010203, uuid.msb());
1264+
}
1265+
1266+
#[test]
1267+
fn test_cql_time_uuid_msb_clears_version() {
1268+
// UUID version nibble should be cleared
1269+
let uuid = Uuid::from_slice(&[0xff; 16]).unwrap();
1270+
let uuid = CqlTimeuuid(uuid);
1271+
1272+
assert_eq!(0x0fffffffffffffff, uuid.msb());
1273+
}
1274+
1275+
#[test]
1276+
fn test_cql_time_uuid_lsb() {
1277+
let uuid = Uuid::from_slice(&[
1278+
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d,
1279+
0x0e, 0x0f,
1280+
])
1281+
.unwrap();
1282+
let uuid = CqlTimeuuid(uuid);
1283+
1284+
assert_eq!(0x08090a0b0c0d0e0f, uuid.lsb());
1285+
1286+
let uuid = Uuid::from_slice(&[0xff; 16]).unwrap();
1287+
let uuid = CqlTimeuuid(uuid);
1288+
1289+
assert_eq!(0xffffffffffffffff, uuid.lsb());
1290+
}
1291+
}

0 commit comments

Comments
 (0)