diff --git a/scylla-cql/src/frame/mod.rs b/scylla-cql/src/frame/mod.rs index 4f8dc8beb..3b132350d 100644 --- a/scylla-cql/src/frame/mod.rs +++ b/scylla-cql/src/frame/mod.rs @@ -302,9 +302,9 @@ mod test { let mut out = Vec::from(&b"Hello"[..]); let uncomp_body = b", World!"; let compression = Compression::Lz4; - let expect = vec![ + let expect = &[ 72, 101, 108, 108, 111, 0, 0, 0, 8, 128, 44, 32, 87, 111, 114, 108, 100, 33, - ]; + ][..]; compress_append(uncomp_body, compression, &mut out).unwrap(); assert_eq!(expect, out); diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index 34edac89d..173bf43a3 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -1730,7 +1730,7 @@ mod tests { #[test] fn test_deserialize_text_types() { - let buf: Vec = vec![0x41]; + let buf = [0x41]; let int_slice = &mut &buf[..]; let ascii_serialized = super::deser_cql_value(&ColumnType::Ascii, int_slice).unwrap(); let text_serialized = super::deser_cql_value(&ColumnType::Text, int_slice).unwrap(); @@ -1742,7 +1742,7 @@ mod tests { fn test_deserialize_uuid_inet_types() { let my_uuid = Uuid::parse_str("00000000000000000000000000000001").unwrap(); - let uuid_buf: Vec = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]; + let uuid_buf = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]; let uuid_slice = &mut &uuid_buf[..]; let uuid_serialize = super::deser_cql_value(&ColumnType::Uuid, uuid_slice).unwrap(); assert_eq!(uuid_serialize, CqlValue::Uuid(my_uuid)); @@ -1753,13 +1753,13 @@ mod tests { assert_eq!(time_uuid_serialize, CqlValue::Timeuuid(my_timeuuid)); let my_ip = "::1".parse().unwrap(); - let ip_buf: Vec = vec![0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]; + let ip_buf = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1]; let ip_slice = &mut &ip_buf[..]; let ip_serialize = super::deser_cql_value(&ColumnType::Inet, ip_slice).unwrap(); assert_eq!(ip_serialize, CqlValue::Inet(my_ip)); let max_ip = "ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff".parse().unwrap(); - let max_ip_buf: Vec = vec![ + let max_ip_buf = [ 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, ]; let max_ip_slice = &mut &max_ip_buf[..]; @@ -1772,12 +1772,12 @@ mod tests { let float: f32 = 0.5; let double: f64 = 2.0; - let float_buf: Vec = vec![63, 0, 0, 0]; + let float_buf = [63, 0, 0, 0]; let float_slice = &mut &float_buf[..]; let float_serialize = super::deser_cql_value(&ColumnType::Float, float_slice).unwrap(); assert_eq!(float_serialize, CqlValue::Float(float)); - let double_buf: Vec = vec![64, 0, 0, 0, 0, 0, 0, 0]; + let double_buf = [64, 0, 0, 0, 0, 0, 0, 0]; let double_slice = &mut &double_buf[..]; let double_serialize = super::deser_cql_value(&ColumnType::Double, double_slice).unwrap(); assert_eq!(double_serialize, CqlValue::Double(double)); @@ -1790,7 +1790,7 @@ mod tests { } #[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))] - fn varint_test_cases_from_spec() -> Vec { + fn varint_test_cases_from_spec() -> [VarintTestCase; 8] { /* Table taken from CQL Binary Protocol v4 spec @@ -1805,7 +1805,7 @@ mod tests { -128 | 0x80 -129 | 0xFF7F */ - vec![ + [ VarintTestCase { value: 0, encoding: vec![0x00], @@ -1906,7 +1906,7 @@ mod tests { #[test] fn test_deserialize_counter() { - let counter: Vec = vec![0, 0, 0, 0, 0, 0, 1, 0]; + let counter = [0, 0, 0, 0, 0, 0, 1, 0]; let counter_slice = &mut &counter[..]; let counter_serialize = super::deser_cql_value(&ColumnType::Counter, counter_slice).unwrap(); @@ -1923,12 +1923,12 @@ mod tests { #[test] fn test_deserialize_bool() { - let bool_buf: Vec = vec![0x00]; + let bool_buf = [0x00]; let bool_slice = &mut &bool_buf[..]; let bool_serialize = super::deser_cql_value(&ColumnType::Boolean, bool_slice).unwrap(); assert_eq!(bool_serialize, CqlValue::Boolean(false)); - let bool_buf: Vec = vec![0x01]; + let bool_buf = [0x01]; let bool_slice = &mut &bool_buf[..]; let bool_serialize = super::deser_cql_value(&ColumnType::Boolean, bool_slice).unwrap(); assert_eq!(bool_serialize, CqlValue::Boolean(true)); @@ -1936,24 +1936,24 @@ mod tests { #[test] fn test_deserialize_int_types() { - let int_buf: Vec = vec![0, 0, 0, 4]; + let int_buf = [0, 0, 0, 4]; let int_slice = &mut &int_buf[..]; let int_serialized = super::deser_cql_value(&ColumnType::Int, int_slice).unwrap(); assert_eq!(int_serialized, CqlValue::Int(4)); - let smallint_buf: Vec = vec![0, 4]; + let smallint_buf = [0, 4]; let smallint_slice = &mut &smallint_buf[..]; let smallint_serialized = super::deser_cql_value(&ColumnType::SmallInt, smallint_slice).unwrap(); assert_eq!(smallint_serialized, CqlValue::SmallInt(4)); - let tinyint_buf: Vec = vec![4]; + let tinyint_buf = [4]; let tinyint_slice = &mut &tinyint_buf[..]; let tinyint_serialized = super::deser_cql_value(&ColumnType::TinyInt, tinyint_slice).unwrap(); assert_eq!(tinyint_serialized, CqlValue::TinyInt(4)); - let bigint_buf: Vec = vec![0, 0, 0, 0, 0, 0, 0, 4]; + let bigint_buf = [0, 0, 0, 0, 0, 0, 0, 4]; let bigint_slice = &mut &bigint_buf[..]; let bigint_serialized = super::deser_cql_value(&ColumnType::BigInt, bigint_slice).unwrap(); assert_eq!(bigint_serialized, CqlValue::BigInt(4)); @@ -2442,7 +2442,7 @@ mod tests { let mut v = Vec::new(); empty.serialize(&mut v).unwrap(); - assert_eq!(v, vec![0, 0, 0, 0]); + assert_eq!(v, &[0, 0, 0, 0]); } #[test] diff --git a/scylla-cql/src/frame/types.rs b/scylla-cql/src/frame/types.rs index 70f28f6c2..edc304789 100644 --- a/scylla-cql/src/frame/types.rs +++ b/scylla-cql/src/frame/types.rs @@ -461,14 +461,14 @@ pub fn write_string_list( #[test] fn type_string_list() { - let val = vec![ + let val = [ "".to_owned(), "CQL_VERSION".to_owned(), "THROW_ON_OVERLOAD".to_owned(), ]; let mut buf = Vec::new(); - write_string_list(&val, &mut buf).unwrap(); + write_string_list(&val[..], &mut buf).unwrap(); assert_eq!(read_string_list(&mut &buf[..]).unwrap(), val); } @@ -697,218 +697,200 @@ fn zig_zag_decode_test() { #[test] fn unsigned_vint_encode_and_decode_test() { - let unsigned_vint_encoding = vec![ - (0, vec![0]), - (1, vec![1]), - (2, vec![2]), - ((1 << 2) - 1, vec![3]), - (1 << 2, vec![4]), - ((1 << 2) + 1, vec![5]), - ((1 << 3) - 1, vec![7]), - (1 << 3, vec![8]), - ((1 << 3) + 1, vec![9]), - ((1 << 4) - 1, vec![15]), - (1 << 4, vec![16]), - ((1 << 4) + 1, vec![17]), - ((1 << 5) - 1, vec![31]), - (1 << 5, vec![32]), - ((1 << 5) + 1, vec![33]), - ((1 << 6) - 1, vec![63]), - (1 << 6, vec![64]), - ((1 << 6) + 1, vec![65]), - ((1 << 7) - 1, vec![127]), - (1 << 7, vec![128, 128]), - ((1 << 7) + 1, vec![128, 129]), - ((1 << 8) - 1, vec![128, 255]), - (1 << 8, vec![129, 0]), - ((1 << 8) + 1, vec![129, 1]), - ((1 << 9) - 1, vec![129, 255]), - (1 << 9, vec![130, 0]), - ((1 << 9) + 1, vec![130, 1]), - ((1 << 10) - 1, vec![131, 255]), - (1 << 10, vec![132, 0]), - ((1 << 10) + 1, vec![132, 1]), - ((1 << 11) - 1, vec![135, 255]), - (1 << 11, vec![136, 0]), - ((1 << 11) + 1, vec![136, 1]), - ((1 << 12) - 1, vec![143, 255]), - (1 << 12, vec![144, 0]), - ((1 << 12) + 1, vec![144, 1]), - ((1 << 13) - 1, vec![159, 255]), - (1 << 13, vec![160, 0]), - ((1 << 13) + 1, vec![160, 1]), - ((1 << 14) - 1, vec![191, 255]), - (1 << 14, vec![192, 64, 0]), - ((1 << 14) + 1, vec![192, 64, 1]), - ((1 << 15) - 1, vec![192, 127, 255]), - (1 << 15, vec![192, 128, 0]), - ((1 << 15) + 1, vec![192, 128, 1]), - ((1 << 16) - 1, vec![192, 255, 255]), - (1 << 16, vec![193, 0, 0]), - ((1 << 16) + 1, vec![193, 0, 1]), - ((1 << 17) - 1, vec![193, 255, 255]), - (1 << 17, vec![194, 0, 0]), - ((1 << 17) + 1, vec![194, 0, 1]), - ((1 << 18) - 1, vec![195, 255, 255]), - (1 << 18, vec![196, 0, 0]), - ((1 << 18) + 1, vec![196, 0, 1]), - ((1 << 19) - 1, vec![199, 255, 255]), - (1 << 19, vec![200, 0, 0]), - ((1 << 19) + 1, vec![200, 0, 1]), - ((1 << 20) - 1, vec![207, 255, 255]), - (1 << 20, vec![208, 0, 0]), - ((1 << 20) + 1, vec![208, 0, 1]), - ((1 << 21) - 1, vec![223, 255, 255]), - (1 << 21, vec![224, 32, 0, 0]), - ((1 << 21) + 1, vec![224, 32, 0, 1]), - ((1 << 22) - 1, vec![224, 63, 255, 255]), - (1 << 22, vec![224, 64, 0, 0]), - ((1 << 22) + 1, vec![224, 64, 0, 1]), - ((1 << 23) - 1, vec![224, 127, 255, 255]), - (1 << 23, vec![224, 128, 0, 0]), - ((1 << 23) + 1, vec![224, 128, 0, 1]), - ((1 << 24) - 1, vec![224, 255, 255, 255]), - (1 << 24, vec![225, 0, 0, 0]), - ((1 << 24) + 1, vec![225, 0, 0, 1]), - ((1 << 25) - 1, vec![225, 255, 255, 255]), - (1 << 25, vec![226, 0, 0, 0]), - ((1 << 25) + 1, vec![226, 0, 0, 1]), - ((1 << 26) - 1, vec![227, 255, 255, 255]), - (1 << 26, vec![228, 0, 0, 0]), - ((1 << 26) + 1, vec![228, 0, 0, 1]), - ((1 << 27) - 1, vec![231, 255, 255, 255]), - (1 << 27, vec![232, 0, 0, 0]), - ((1 << 27) + 1, vec![232, 0, 0, 1]), - ((1 << 28) - 1, vec![239, 255, 255, 255]), - (1 << 28, vec![240, 16, 0, 0, 0]), - ((1 << 28) + 1, vec![240, 16, 0, 0, 1]), - ((1 << 29) - 1, vec![240, 31, 255, 255, 255]), - (1 << 29, vec![240, 32, 0, 0, 0]), - ((1 << 29) + 1, vec![240, 32, 0, 0, 1]), - ((1 << 30) - 1, vec![240, 63, 255, 255, 255]), - (1 << 30, vec![240, 64, 0, 0, 0]), - ((1 << 30) + 1, vec![240, 64, 0, 0, 1]), - ((1 << 31) - 1, vec![240, 127, 255, 255, 255]), - (1 << 31, vec![240, 128, 0, 0, 0]), - ((1 << 31) + 1, vec![240, 128, 0, 0, 1]), - ((1 << 32) - 1, vec![240, 255, 255, 255, 255]), - (1 << 32, vec![241, 0, 0, 0, 0]), - ((1 << 32) + 1, vec![241, 0, 0, 0, 1]), - ((1 << 33) - 1, vec![241, 255, 255, 255, 255]), - (1 << 33, vec![242, 0, 0, 0, 0]), - ((1 << 33) + 1, vec![242, 0, 0, 0, 1]), - ((1 << 34) - 1, vec![243, 255, 255, 255, 255]), - (1 << 34, vec![244, 0, 0, 0, 0]), - ((1 << 34) + 1, vec![244, 0, 0, 0, 1]), - ((1 << 35) - 1, vec![247, 255, 255, 255, 255]), - (1 << 35, vec![248, 8, 0, 0, 0, 0]), - ((1 << 35) + 1, vec![248, 8, 0, 0, 0, 1]), - ((1 << 36) - 1, vec![248, 15, 255, 255, 255, 255]), - (1 << 36, vec![248, 16, 0, 0, 0, 0]), - ((1 << 36) + 1, vec![248, 16, 0, 0, 0, 1]), - ((1 << 37) - 1, vec![248, 31, 255, 255, 255, 255]), - (1 << 37, vec![248, 32, 0, 0, 0, 0]), - ((1 << 37) + 1, vec![248, 32, 0, 0, 0, 1]), - ((1 << 38) - 1, vec![248, 63, 255, 255, 255, 255]), - (1 << 38, vec![248, 64, 0, 0, 0, 0]), - ((1 << 38) + 1, vec![248, 64, 0, 0, 0, 1]), - ((1 << 39) - 1, vec![248, 127, 255, 255, 255, 255]), - (1 << 39, vec![248, 128, 0, 0, 0, 0]), - ((1 << 39) + 1, vec![248, 128, 0, 0, 0, 1]), - ((1 << 40) - 1, vec![248, 255, 255, 255, 255, 255]), - (1 << 40, vec![249, 0, 0, 0, 0, 0]), - ((1 << 40) + 1, vec![249, 0, 0, 0, 0, 1]), - ((1 << 41) - 1, vec![249, 255, 255, 255, 255, 255]), - (1 << 41, vec![250, 0, 0, 0, 0, 0]), - ((1 << 41) + 1, vec![250, 0, 0, 0, 0, 1]), - ((1 << 42) - 1, vec![251, 255, 255, 255, 255, 255]), - (1 << 42, vec![252, 4, 0, 0, 0, 0, 0]), - ((1 << 42) + 1, vec![252, 4, 0, 0, 0, 0, 1]), - ((1 << 43) - 1, vec![252, 7, 255, 255, 255, 255, 255]), - (1 << 43, vec![252, 8, 0, 0, 0, 0, 0]), - ((1 << 43) + 1, vec![252, 8, 0, 0, 0, 0, 1]), - ((1 << 44) - 1, vec![252, 15, 255, 255, 255, 255, 255]), - (1 << 44, vec![252, 16, 0, 0, 0, 0, 0]), - ((1 << 44) + 1, vec![252, 16, 0, 0, 0, 0, 1]), - ((1 << 45) - 1, vec![252, 31, 255, 255, 255, 255, 255]), - (1 << 45, vec![252, 32, 0, 0, 0, 0, 0]), - ((1 << 45) + 1, vec![252, 32, 0, 0, 0, 0, 1]), - ((1 << 46) - 1, vec![252, 63, 255, 255, 255, 255, 255]), - (1 << 46, vec![252, 64, 0, 0, 0, 0, 0]), - ((1 << 46) + 1, vec![252, 64, 0, 0, 0, 0, 1]), - ((1 << 47) - 1, vec![252, 127, 255, 255, 255, 255, 255]), - (1 << 47, vec![252, 128, 0, 0, 0, 0, 0]), - ((1 << 47) + 1, vec![252, 128, 0, 0, 0, 0, 1]), - ((1 << 48) - 1, vec![252, 255, 255, 255, 255, 255, 255]), - (1 << 48, vec![253, 0, 0, 0, 0, 0, 0]), - ((1 << 48) + 1, vec![253, 0, 0, 0, 0, 0, 1]), - ((1 << 49) - 1, vec![253, 255, 255, 255, 255, 255, 255]), - (1 << 49, vec![254, 2, 0, 0, 0, 0, 0, 0]), - ((1 << 49) + 1, vec![254, 2, 0, 0, 0, 0, 0, 1]), - ((1 << 50) - 1, vec![254, 3, 255, 255, 255, 255, 255, 255]), - (1 << 50, vec![254, 4, 0, 0, 0, 0, 0, 0]), - ((1 << 50) + 1, vec![254, 4, 0, 0, 0, 0, 0, 1]), - ((1 << 51) - 1, vec![254, 7, 255, 255, 255, 255, 255, 255]), - (1 << 51, vec![254, 8, 0, 0, 0, 0, 0, 0]), - ((1 << 51) + 1, vec![254, 8, 0, 0, 0, 0, 0, 1]), - ((1 << 52) - 1, vec![254, 15, 255, 255, 255, 255, 255, 255]), - (1 << 52, vec![254, 16, 0, 0, 0, 0, 0, 0]), - ((1 << 52) + 1, vec![254, 16, 0, 0, 0, 0, 0, 1]), - ((1 << 53) - 1, vec![254, 31, 255, 255, 255, 255, 255, 255]), - (1 << 53, vec![254, 32, 0, 0, 0, 0, 0, 0]), - ((1 << 53) + 1, vec![254, 32, 0, 0, 0, 0, 0, 1]), - ((1 << 54) - 1, vec![254, 63, 255, 255, 255, 255, 255, 255]), - (1 << 54, vec![254, 64, 0, 0, 0, 0, 0, 0]), - ((1 << 54) + 1, vec![254, 64, 0, 0, 0, 0, 0, 1]), - ((1 << 55) - 1, vec![254, 127, 255, 255, 255, 255, 255, 255]), - (1 << 55, vec![254, 128, 0, 0, 0, 0, 0, 0]), - ((1 << 55) + 1, vec![254, 128, 0, 0, 0, 0, 0, 1]), - ((1 << 56) - 1, vec![254, 255, 255, 255, 255, 255, 255, 255]), - (1 << 56, vec![255, 1, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 56) + 1, vec![255, 1, 0, 0, 0, 0, 0, 0, 1]), - ( - (1 << 57) - 1, - vec![255, 1, 255, 255, 255, 255, 255, 255, 255], - ), - (1 << 57, vec![255, 2, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 57) + 1, vec![255, 2, 0, 0, 0, 0, 0, 0, 1]), - ( - (1 << 58) - 1, - vec![255, 3, 255, 255, 255, 255, 255, 255, 255], - ), - (1 << 58, vec![255, 4, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 58) + 1, vec![255, 4, 0, 0, 0, 0, 0, 0, 1]), - ( - (1 << 59) - 1, - vec![255, 7, 255, 255, 255, 255, 255, 255, 255], - ), - (1 << 59, vec![255, 8, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 59) + 1, vec![255, 8, 0, 0, 0, 0, 0, 0, 1]), - ( - (1 << 60) - 1, - vec![255, 15, 255, 255, 255, 255, 255, 255, 255], - ), - (1 << 60, vec![255, 16, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 60) + 1, vec![255, 16, 0, 0, 0, 0, 0, 0, 1]), - ( - (1 << 61) - 1, - vec![255, 31, 255, 255, 255, 255, 255, 255, 255], - ), - (1 << 61, vec![255, 32, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 61) + 1, vec![255, 32, 0, 0, 0, 0, 0, 0, 1]), - ( - (1 << 62) - 1, - vec![255, 63, 255, 255, 255, 255, 255, 255, 255], - ), - (1 << 62, vec![255, 64, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 62) + 1, vec![255, 64, 0, 0, 0, 0, 0, 0, 1]), + let unsigned_vint_encoding = [ + (0, &[0][..]), + (1, &[1]), + (2, &[2]), + ((1 << 2) - 1, &[3]), + (1 << 2, &[4]), + ((1 << 2) + 1, &[5]), + ((1 << 3) - 1, &[7]), + (1 << 3, &[8]), + ((1 << 3) + 1, &[9]), + ((1 << 4) - 1, &[15]), + (1 << 4, &[16]), + ((1 << 4) + 1, &[17]), + ((1 << 5) - 1, &[31]), + (1 << 5, &[32]), + ((1 << 5) + 1, &[33]), + ((1 << 6) - 1, &[63]), + (1 << 6, &[64]), + ((1 << 6) + 1, &[65]), + ((1 << 7) - 1, &[127]), + (1 << 7, &[128, 128]), + ((1 << 7) + 1, &[128, 129]), + ((1 << 8) - 1, &[128, 255]), + (1 << 8, &[129, 0]), + ((1 << 8) + 1, &[129, 1]), + ((1 << 9) - 1, &[129, 255]), + (1 << 9, &[130, 0]), + ((1 << 9) + 1, &[130, 1]), + ((1 << 10) - 1, &[131, 255]), + (1 << 10, &[132, 0]), + ((1 << 10) + 1, &[2, 1]), + ((1 << 11) - 1, &[5, 255]), + (1 << 11, &[136, 0]), + ((1 << 11) + 1, &[136, 1]), + ((1 << 12) - 1, &[143, 255]), + (1 << 12, &[4, 0]), + ((1 << 12) + 1, &[144, 1]), + ((1 << 13) - 1, &[159, 255]), + (1 << 13, &[0, 0]), + ((1 << 13) + 1, &[0, 1]), + ((1 << 14) - 1, &[191, 255]), + (1 << 14, &[192, 64, 0]), + ((1 << 14) + 1, &[192, 64, 1]), + ((1 << 15) - 1, &[192, 127, 255]), + (1 << 15, &[2, 128, 0]), + ((1 << 15) + 1, &[192, 128, 1]), + ((1 << 16) - 1, &[192, 255, 255]), + (1 << 16, &[193, 0, 0]), + ((1 << 16) + 1, &[193, 0, 1]), + ((1 << 17) - 1, &[193, 255, 255]), + (1 << 17, &[194, 0, 0]), + ((1 << 17) + 1, &[194, 0, 1]), + ((1 << 18) - 1, &[195, 255, 255]), + (1 << 18, &[196, 0, 0]), + ((1 << 18) + 1, &[196, 0, 1]), + ((1 << 19) - 1, &[199, 255, 255]), + (1 << 19, &[200, 0, 0]), + ((1 << 19) + 1, &[200, 0, 1]), + ((1 << 20) - 1, &[207, 255, 255]), + (1 << 20, &[208, 0, 0]), + ((1 << 20) + 1, &[208, 0, 1]), + ((1 << 21) - 1, &[223, 255, 255]), + (1 << 21, &[224, 32, 0, 0]), + ((1 << 21) + 1, &[224, 32, 0, 1]), + ((1 << 22) - 1, &[4, 63, 255, 255]), + (1 << 22, &[224, 64, 0, 0]), + ((1 << 22) + 1, &[224, 64, 0, 1]), + ((1 << 23) - 1, &[224, 127, 255, 255]), + (1 << 23, &[128, 0, 0]), + ((1 << 23) + 1, &[4, 128, 0, 1]), + ((1 << 24) - 1, &[224, 255, 255, 255]), + (1 << 24, &[225, 0, 0, 0]), + ((1 << 24) + 1, &[225, 0, 0, 1]), + ((1 << 25) - 1, &[225, 255, 255, 255]), + (1 << 25, &[226, 0, 0, 0]), + ((1 << 25) + 1, &[226, 0, 0, 1]), + ((1 << 26) - 1, &[227, 255, 255, 255]), + (1 << 26, &[8, 0, 0, 0]), + ((1 << 26) + 1, &[228, 0, 0, 1]), + ((1 << 27) - 1, &[231, 255, 255, 255]), + (1 << 27, &[232, 0, 0, 0]), + ((1 << 27) + 1, &[232, 0, 0, 1]), + ((1 << 28) - 1, &[239, 255, 255, 255]), + (1 << 28, &[240, 16, 0, 0, 0]), + ((1 << 28) + 1, &[240, 16, 0, 0, 1]), + ((1 << 29) - 1, &[31, 255, 255, 255]), + (1 << 29, &[240, 32, 0, 0, 0]), + ((1 << 29) + 1, &[240, 32, 0, 0, 1]), + ((1 << 30) - 1, &[240, 63, 255, 255, 255]), + (1 << 30, &[240, 64, 0, 0, 0]), + ((1 << 30) + 1, &[240, 64, 0, 0, 1]), + ((1 << 31) - 1, &[240, 127, 255, 255, 255]), + (1 << 31, &[240, 128, 0, 0, 0]), + ((1 << 31) + 1, &[240, 128, 0, 0, 1]), + ((1 << 32) - 1, &[240, 255, 255, 255, 255]), + (1 << 32, &[241, 0, 0, 0, 0]), + ((1 << 32) + 1, &[241, 0, 0, 0, 1]), + ((1 << 33) - 1, &[241, 255, 255, 255, 255]), + (1 << 33, &[242, 0, 0, 0, 0]), + ((1 << 33) + 1, &[242, 0, 0, 0, 1]), + ((1 << 34) - 1, &[243, 255, 255, 255, 255]), + (1 << 34, &[244, 0, 0, 0, 0]), + ((1 << 34) + 1, &[244, 0, 0, 0, 1]), + ((1 << 35) - 1, &[247, 255, 255, 255, 255]), + (1 << 35, &[248, 8, 0, 0, 0, 0]), + ((1 << 35) + 1, &[248, 8, 0, 0, 0, 1]), + ((1 << 36) - 1, &[248, 15, 255, 255, 255, 255]), + (1 << 36, &[248, 16, 0, 0, 0, 0]), + ((1 << 36) + 1, &[248, 16, 0, 0, 0, 1]), + ((1 << 37) - 1, &[248, 31, 255, 255, 255, 255]), + (1 << 37, &[248, 32, 0, 0, 0, 0]), + ((1 << 37) + 1, &[248, 32, 0, 0, 0, 1]), + ((1 << 38) - 1, &[248, 63, 255, 255, 255, 255]), + (1 << 38, &[248, 64, 0, 0, 0, 0]), + ((1 << 38) + 1, &[248, 64, 0, 0, 0, 1]), + ((1 << 39) - 1, &[248, 127, 255, 255, 255, 255]), + (1 << 39, &[248, 128, 0, 0, 0, 0]), + ((1 << 39) + 1, &[248, 128, 0, 0, 0, 1]), + ((1 << 40) - 1, &[248, 255, 255, 255, 255, 255]), + (1 << 40, &[249, 0, 0, 0, 0, 0]), + ((1 << 40) + 1, &[249, 0, 0, 0, 0, 1]), + ((1 << 41) - 1, &[249, 255, 255, 255, 255, 255]), + (1 << 41, &[250, 0, 0, 0, 0, 0]), + ((1 << 41) + 1, &[250, 0, 0, 0, 0, 1]), + ((1 << 42) - 1, &[251, 255, 255, 255, 255, 255]), + (1 << 42, &[252, 4, 0, 0, 0, 0, 0]), + ((1 << 42) + 1, &[252, 4, 0, 0, 0, 0, 1]), + ((1 << 43) - 1, &[252, 7, 255, 255, 255, 255, 255]), + (1 << 43, &[252, 8, 0, 0, 0, 0, 0]), + ((1 << 43) + 1, &[252, 8, 0, 0, 0, 0, 1]), + ((1 << 44) - 1, &[252, 15, 255, 255, 255, 255, 255]), + (1 << 44, &[252, 16, 0, 0, 0, 0, 0]), + ((1 << 44) + 1, &[252, 16, 0, 0, 0, 0, 1]), + ((1 << 45) - 1, &[252, 31, 255, 255, 255, 255, 255]), + (1 << 45, &[252, 32, 0, 0, 0, 0, 0]), + ((1 << 45) + 1, &[252, 32, 0, 0, 0, 0, 1]), + ((1 << 46) - 1, &[252, 63, 255, 255, 255, 255, 255]), + (1 << 46, &[252, 64, 0, 0, 0, 0, 0]), + ((1 << 46) + 1, &[252, 64, 0, 0, 0, 0, 1]), + ((1 << 47) - 1, &[252, 127, 255, 255, 255, 255, 255]), + (1 << 47, &[252, 128, 0, 0, 0, 0, 0]), + ((1 << 47) + 1, &[252, 128, 0, 0, 0, 0, 1]), + ((1 << 48) - 1, &[252, 255, 255, 255, 255, 255, 255]), + (1 << 48, &[253, 0, 0, 0, 0, 0, 0]), + ((1 << 48) + 1, &[253, 0, 0, 0, 0, 0, 1]), + ((1 << 49) - 1, &[253, 255, 255, 255, 255, 255, 255]), + (1 << 49, &[254, 2, 0, 0, 0, 0, 0, 0]), + ((1 << 49) + 1, &[254, 2, 0, 0, 0, 0, 0, 1]), + ((1 << 50) - 1, &[254, 3, 255, 255, 255, 255, 255, 255]), + (1 << 50, &[254, 4, 0, 0, 0, 0, 0, 0]), + ((1 << 50) + 1, &[254, 4, 0, 0, 0, 0, 0, 1]), + ((1 << 51) - 1, &[254, 7, 255, 255, 255, 255, 255, 255]), + (1 << 51, &[254, 8, 0, 0, 0, 0, 0, 0]), + ((1 << 51) + 1, &[254, 8, 0, 0, 0, 0, 0, 1]), + ((1 << 52) - 1, &[254, 15, 255, 255, 255, 255, 255, 255]), + (1 << 52, &[254, 16, 0, 0, 0, 0, 0, 0]), + ((1 << 52) + 1, &[254, 16, 0, 0, 0, 0, 0, 1]), + ((1 << 53) - 1, &[254, 31, 255, 255, 255, 255, 255, 255]), + (1 << 53, &[254, 32, 0, 0, 0, 0, 0, 0]), + ((1 << 53) + 1, &[254, 32, 0, 0, 0, 0, 0, 1]), + ((1 << 54) - 1, &[254, 63, 255, 255, 255, 255, 255, 255]), + (1 << 54, &[254, 64, 0, 0, 0, 0, 0, 0]), + ((1 << 54) + 1, &[254, 64, 0, 0, 0, 0, 0, 1]), + ((1 << 55) - 1, &[254, 127, 255, 255, 255, 255, 255, 255]), + (1 << 55, &[254, 128, 0, 0, 0, 0, 0, 0]), + ((1 << 55) + 1, &[254, 128, 0, 0, 0, 0, 0, 1]), + ((1 << 56) - 1, &[254, 255, 255, 255, 255, 255, 255, 255]), + (1 << 56, &[255, 1, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 56) + 1, &[255, 1, 0, 0, 0, 0, 0, 0, 1]), + ((1 << 57) - 1, &[255, 1, 255, 255, 255, 255, 255, 255, 255]), + (1 << 57, &[255, 2, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 57) + 1, &[255, 2, 0, 0, 0, 0, 0, 0, 1]), + ((1 << 58) - 1, &[255, 3, 255, 255, 255, 255, 255, 255, 255]), + (1 << 58, &[255, 4, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 58) + 1, &[255, 4, 0, 0, 0, 0, 0, 0, 1]), + ((1 << 59) - 1, &[255, 7, 255, 255, 255, 255, 255, 255, 255]), + (1 << 59, &[255, 8, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 59) + 1, &[255, 8, 0, 0, 0, 0, 0, 0, 1]), + ((1 << 60) - 1, &[5, 15, 255, 255, 255, 255, 255, 255, 255]), + (1 << 60, &[255, 16, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 60) + 1, &[255, 16, 0, 0, 0, 0, 0, 0, 1]), + ((1 << 61) - 1, &[255, 31, 255, 255, 255, 255, 255, 255, 255]), + (1 << 61, &[255, 32, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 61) + 1, &[255, 32, 0, 0, 0, 0, 0, 0, 1]), + ((1 << 62) - 1, &[255, 63, 255, 255, 255, 255, 255, 255, 255]), + (1 << 62, &[255, 64, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 62) + 1, &[255, 64, 0, 0, 0, 0, 0, 0, 1]), ( (1 << 63) - 1, - vec![255, 127, 255, 255, 255, 255, 255, 255, 255], + &[255, 127, 255, 255, 255, 255, 255, 255, 255], ), - (1 << 63, vec![255, 128, 0, 0, 0, 0, 0, 0, 0]), - ((1 << 63) + 1, vec![255, 128, 0, 0, 0, 0, 0, 0, 1]), - (u64::MAX, vec![255, 255, 255, 255, 255, 255, 255, 255, 255]), + (1 << 63, &[255, 128, 0, 0, 0, 0, 0, 0, 0]), + ((1 << 63) + 1, &[255, 128, 0, 0, 0, 0, 0, 0, 1]), + (u64::MAX, &[255, 255, 255, 255, 255, 255, 255, 255, 255]), ]; let mut buf = Vec::new(); diff --git a/scylla-cql/src/frame/value_tests.rs b/scylla-cql/src/frame/value_tests.rs index 62d998cbf..90d5f884d 100644 --- a/scylla-cql/src/frame/value_tests.rs +++ b/scylla-cql/src/frame/value_tests.rs @@ -52,24 +52,24 @@ fn compute_hash(x: &T) -> u64 { #[test] fn boolean_serialization() { - assert_eq!(serialized(true, ColumnType::Boolean), vec![0, 0, 0, 1, 1]); - assert_eq!(serialized(false, ColumnType::Boolean), vec![0, 0, 0, 1, 0]); + assert_eq!(serialized(true, ColumnType::Boolean), &[0, 0, 0, 1, 1]); + assert_eq!(serialized(false, ColumnType::Boolean), &[0, 0, 0, 1, 0]); } #[test] fn fixed_integral_serialization() { - assert_eq!(serialized(8_i8, ColumnType::TinyInt), vec![0, 0, 0, 1, 8]); + assert_eq!(serialized(8_i8, ColumnType::TinyInt), &[0, 0, 0, 1, 8]); assert_eq!( serialized(16_i16, ColumnType::SmallInt), - vec![0, 0, 0, 2, 0, 16] + &[0, 0, 0, 2, 0, 16] ); assert_eq!( serialized(32_i32, ColumnType::Int), - vec![0, 0, 0, 4, 0, 0, 0, 32] + &[0, 0, 0, 4, 0, 0, 0, 32] ); assert_eq!( serialized(64_i64, ColumnType::BigInt), - vec![0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 64] + &[0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0, 64] ); } @@ -77,7 +77,7 @@ fn fixed_integral_serialization() { fn counter_serialization() { assert_eq!( serialized(0x0123456789abcdef_i64, ColumnType::BigInt), - vec![0, 0, 0, 8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] + &[0, 0, 0, 8, 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef] ); } @@ -241,29 +241,26 @@ fn floating_point_serialization() { fn text_serialization() { assert_eq!( serialized("abc", ColumnType::Text), - vec![0, 0, 0, 3, 97, 98, 99] + &[0, 0, 0, 3, 97, 98, 99] ); assert_eq!( serialized("abc".to_string(), ColumnType::Ascii), - vec![0, 0, 0, 3, 97, 98, 99] + &[0, 0, 0, 3, 97, 98, 99] ); } #[test] fn u8_array_serialization() { let val = [1u8; 4]; - assert_eq!( - serialized(val, ColumnType::Blob), - vec![0, 0, 0, 4, 1, 1, 1, 1] - ); + assert_eq!(serialized(val, ColumnType::Blob), &[0, 0, 0, 4, 1, 1, 1, 1]); } #[test] fn u8_slice_serialization() { - let val = vec![1u8, 1, 1, 1]; + let val = &[1u8, 1, 1, 1]; assert_eq!( serialized(val.as_slice(), ColumnType::Blob), - vec![0, 0, 0, 4, 1, 1, 1, 1] + &[0, 0, 0, 4, 1, 1, 1, 1] ); } @@ -271,21 +268,18 @@ fn u8_slice_serialization() { fn cql_date_serialization() { assert_eq!( serialized(CqlDate(0), ColumnType::Date), - vec![0, 0, 0, 4, 0, 0, 0, 0] + &[0, 0, 0, 4, 0, 0, 0, 0] ); assert_eq!( serialized(CqlDate(u32::MAX), ColumnType::Date), - vec![0, 0, 0, 4, 255, 255, 255, 255] + &[0, 0, 0, 4, 255, 255, 255, 255] ); } #[test] fn vec_u8_slice_serialization() { - let val = vec![1u8, 1, 1, 1]; - assert_eq!( - serialized(val, ColumnType::Blob), - vec![0, 0, 0, 4, 1, 1, 1, 1] - ); + let val = &[1u8, 1, 1, 1]; + assert_eq!(serialized(val, ColumnType::Blob), &[0, 0, 0, 4, 1, 1, 1, 1]); } #[test] @@ -293,13 +287,13 @@ fn ipaddr_serialization() { let ipv4 = IpAddr::V4(Ipv4Addr::new(1, 2, 3, 4)); assert_eq!( serialized(ipv4, ColumnType::Inet), - vec![0, 0, 0, 4, 1, 2, 3, 4] + &[0, 0, 0, 4, 1, 2, 3, 4] ); let ipv6 = IpAddr::V6(Ipv6Addr::new(1, 2, 3, 4, 5, 6, 7, 8)); assert_eq!( serialized(ipv6, ColumnType::Inet), - vec![ + &[ 0, 0, 0, 16, // serialized size 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, // contents ] @@ -314,7 +308,7 @@ fn naive_date_04_serialization() { let unix_epoch: NaiveDate = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap(); assert_eq!( serialized(unix_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 128, 0, 0, 0] + &[0, 0, 0, 4, 128, 0, 0, 0] ); assert_eq!(2_u32.pow(31).to_be_bytes(), [128, 0, 0, 0]); @@ -322,7 +316,7 @@ fn naive_date_04_serialization() { let before_epoch: NaiveDate = NaiveDate::from_ymd_opt(1969, 12, 2).unwrap(); assert_eq!( serialized(before_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 127, 255, 255, 226] + &[0, 0, 0, 4, 127, 255, 255, 226] ); assert_eq!((2_u32.pow(31) - 30).to_be_bytes(), [127, 255, 255, 226]); @@ -330,7 +324,7 @@ fn naive_date_04_serialization() { let after_epoch: NaiveDate = NaiveDate::from_ymd_opt(1970, 1, 31).unwrap(); assert_eq!( serialized(after_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 128, 0, 0, 30] + &[0, 0, 0, 4, 128, 0, 0, 30] ); assert_eq!((2_u32.pow(31) + 30).to_be_bytes(), [128, 0, 0, 30]); } @@ -342,7 +336,7 @@ fn date_03_serialization() { let unix_epoch = time_03::Date::from_ordinal_date(1970, 1).unwrap(); assert_eq!( serialized(unix_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 128, 0, 0, 0] + &[0, 0, 0, 4, 128, 0, 0, 0] ); assert_eq!(2_u32.pow(31).to_be_bytes(), [128, 0, 0, 0]); @@ -351,7 +345,7 @@ fn date_03_serialization() { time_03::Date::from_calendar_date(1969, time_03::Month::December, 2).unwrap(); assert_eq!( serialized(before_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 127, 255, 255, 226] + &[0, 0, 0, 4, 127, 255, 255, 226] ); assert_eq!((2_u32.pow(31) - 30).to_be_bytes(), [127, 255, 255, 226]); @@ -359,7 +353,7 @@ fn date_03_serialization() { let after_epoch = time_03::Date::from_calendar_date(1970, time_03::Month::January, 31).unwrap(); assert_eq!( serialized(after_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 128, 0, 0, 30] + &[0, 0, 0, 4, 128, 0, 0, 30] ); assert_eq!((2_u32.pow(31) + 30).to_be_bytes(), [128, 0, 0, 30]); @@ -373,7 +367,7 @@ fn date_03_serialization() { ); assert_eq!( serialized(long_before_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 127, 189, 75, 125] + &[0, 0, 0, 4, 127, 189, 75, 125] ); // Max date represented by time_03::Date (without large-dates feature) @@ -386,7 +380,7 @@ fn date_03_serialization() { ); assert_eq!( serialized(long_after_epoch, ColumnType::Date), - vec![0, 0, 0, 4, 128, 44, 192, 160] + &[0, 0, 0, 4, 128, 44, 192, 160] ); } @@ -653,25 +647,22 @@ fn cqlduration_serialization() { }; assert_eq!( serialized(duration, ColumnType::Duration), - vec![0, 0, 0, 3, 2, 4, 6] + &[0, 0, 0, 3, 2, 4, 6] ); } #[test] fn box_serialization() { let x: Box = Box::new(123); - assert_eq!( - serialized(x, ColumnType::Int), - vec![0, 0, 0, 4, 0, 0, 0, 123] - ); + assert_eq!(serialized(x, ColumnType::Int), &[0, 0, 0, 4, 0, 0, 0, 123]); } #[test] fn vec_set_serialization() { - let m = vec!["ala", "ma", "kota"]; + let m = &["ala", "ma", "kota"][..]; assert_eq!( serialized(m, ColumnType::Set(Box::new(ColumnType::Text))), - vec![ + &[ 0, 0, 0, 25, // 25 bytes 0, 0, 0, 3, // 3 items 0, 0, 0, 3, 97, 108, 97, // ala @@ -683,10 +674,10 @@ fn vec_set_serialization() { #[test] fn slice_set_serialization() { - let m = ["ala", "ma", "kota"]; + let m = &["ala", "ma", "kota"][..]; assert_eq!( serialized(m.as_ref(), ColumnType::Set(Box::new(ColumnType::Text))), - vec![ + &[ 0, 0, 0, 25, // 25 bytes 0, 0, 0, 3, // 3 items 0, 0, 0, 3, 97, 108, 97, // ala @@ -721,7 +712,7 @@ fn hashset_serialization() { let m: HashSet<&'static str, DumbBuildHasher> = ["ala", "ma", "kota"].into_iter().collect(); assert_eq!( serialized(m, ColumnType::Set(Box::new(ColumnType::Text))), - vec![ + &[ 0, 0, 0, 25, // 25 bytes 0, 0, 0, 3, // 3 items 0, 0, 0, 2, 109, 97, // ma @@ -740,7 +731,7 @@ fn hashmap_serialization() { m, ColumnType::Map(Box::new(ColumnType::Text), Box::new(ColumnType::Int)) ), - vec![ + &[ 0, 0, 0, 49, // 49 bytes 0, 0, 0, 3, // 3 items 0, 0, 0, 2, 109, 97, // ma @@ -758,7 +749,7 @@ fn btreeset_serialization() { let m: BTreeSet<&'static str> = ["ala", "ma", "kota"].into_iter().collect(); assert_eq!( serialized(m, ColumnType::Set(Box::new(ColumnType::Text))), - vec![ + &[ 0, 0, 0, 25, // 25 bytes 0, 0, 0, 3, // 3 items 0, 0, 0, 3, 97, 108, 97, // ala @@ -776,7 +767,7 @@ fn btreemap_serialization() { m, ColumnType::Map(Box::new(ColumnType::Text), Box::new(ColumnType::Int)) ), - vec![ + &[ 0, 0, 0, 49, // 49 bytes 0, 0, 0, 3, // 3 items 0, 0, 0, 3, 97, 108, 97, // ala @@ -795,10 +786,7 @@ fn cqlvalue_serialization() { // e.g. UDTs or tuples. // Empty - assert_eq!( - serialized(CqlValue::Empty, ColumnType::Int), - vec![0, 0, 0, 0], - ); + assert_eq!(serialized(CqlValue::Empty, ColumnType::Int), &[0, 0, 0, 0],); // UDTs let udt = CqlValue::UserDefinedType { @@ -820,7 +808,7 @@ fn cqlvalue_serialization() { assert_eq!( serialized(udt, typ.clone()), - vec![ + &[ 0, 0, 0, 12, // size of the whole thing 0, 0, 0, 4, 0, 0, 0, 123, // foo: 123_i32 255, 255, 255, 255, // bar: null @@ -840,7 +828,7 @@ fn cqlvalue_serialization() { assert_eq!( serialized_only_new(udt, typ.clone()), - vec![ + &[ 0, 0, 0, 12, // size of the whole thing 0, 0, 0, 4, 0, 0, 0, 123, // foo: 123_i32 255, 255, 255, 255, // bar: null @@ -852,7 +840,7 @@ fn cqlvalue_serialization() { let typ = ColumnType::Tuple(vec![ColumnType::Int, ColumnType::Text]); assert_eq!( serialized(tup, typ), - vec![ + &[ 0, 0, 0, 12, // size of the whole thing 0, 0, 0, 4, 0, 0, 0, 123, // 123_i32 255, 255, 255, 255, // null @@ -867,7 +855,7 @@ fn cqlvalue_serialization() { let typ = ColumnType::Tuple(vec![ColumnType::Int, ColumnType::Text, ColumnType::Counter]); assert_eq!( serialized(tup, typ), - vec![ + &[ 0, 0, 0, 12, // size of the whole thing 0, 0, 0, 4, 0, 0, 0, 123, // 123_i32 255, 255, 255, 255, // null @@ -881,7 +869,7 @@ fn secret_serialization() { let secret = secrecy_08::Secret::new(987654i32); assert_eq!( serialized(secret, ColumnType::Int), - vec![0, 0, 0, 4, 0x00, 0x0f, 0x12, 0x06] + &[0, 0, 0, 4, 0x00, 0x0f, 0x12, 0x06] ); } @@ -889,7 +877,7 @@ fn secret_serialization() { fn option_value() { assert_eq!( serialized(Some(32_i32), ColumnType::Int), - vec![0, 0, 0, 4, 0, 0, 0, 32] + &[0, 0, 0, 4, 0, 0, 0, 32] ); let null_i32: Option = None; assert_eq!( @@ -914,7 +902,7 @@ fn unset_value() { let set_i32: MaybeUnset = MaybeUnset::Set(32); assert_eq!( serialized(set_i32, ColumnType::Int), - vec![0, 0, 0, 4, 0, 0, 0, 32] + &[0, 0, 0, 4, 0, 0, 0, 32] ); } @@ -945,7 +933,7 @@ fn empty_serialized_values() { let mut empty_request = Vec::::new(); EMPTY.write_to_request(&mut empty_request); - assert_eq!(empty_request, vec![0, 0]); + assert_eq!(empty_request, &[0, 0]); } #[test] @@ -961,11 +949,11 @@ fn serialized_values() { let mut request = Vec::::new(); values.write_to_request(&mut request); - assert_eq!(request, vec![0, 1, 0, 0, 0, 1, 8]); + assert_eq!(request, &[0, 1, 0, 0, 0, 1, 8]); assert_eq!( values.iter().collect::>(), - vec![RawValue::Value([8].as_ref())] + &[RawValue::Value([8].as_ref())] ); } @@ -977,11 +965,11 @@ fn serialized_values() { let mut request = Vec::::new(); values.write_to_request(&mut request); - assert_eq!(request, vec![0, 2, 0, 0, 0, 1, 8, 0, 0, 0, 2, 0, 16]); + assert_eq!(request, &[0, 2, 0, 0, 0, 1, 8, 0, 0, 0, 2, 0, 16]); assert_eq!( values.iter().collect::>(), - vec![ + &[ RawValue::Value([8].as_ref()), RawValue::Value([0, 16].as_ref()) ] @@ -1012,11 +1000,11 @@ fn serialized_values() { let mut request = Vec::::new(); values.write_to_request(&mut request); - assert_eq!(request, vec![0, 2, 0, 0, 0, 1, 8, 0, 0, 0, 2, 0, 16]); + assert_eq!(request, &[0, 2, 0, 0, 0, 1, 8, 0, 0, 0, 2, 0, 16]); assert_eq!( values.iter().collect::>(), - vec![ + &[ RawValue::Value([8].as_ref()), RawValue::Value([0, 16].as_ref()) ] @@ -1051,7 +1039,7 @@ fn slice_value_list() { assert_eq!( serialized.iter().collect::>(), - vec![ + &[ RawValue::Value([0, 0, 0, 1].as_ref()), RawValue::Value([0, 0, 0, 2].as_ref()), RawValue::Value([0, 0, 0, 3].as_ref()) @@ -1061,7 +1049,7 @@ fn slice_value_list() { #[test] fn vec_value_list() { - let values: Vec = vec![1, 2, 3]; + let values = &[1, 2, 3][..]; let cols = &[ col_spec("ala", ColumnType::Int), col_spec("ma", ColumnType::Int), @@ -1071,7 +1059,7 @@ fn vec_value_list() { assert_eq!( serialized.iter().collect::>(), - vec![ + &[ RawValue::Value([0, 0, 0, 1].as_ref()), RawValue::Value([0, 0, 0, 2].as_ref()), RawValue::Value([0, 0, 0, 3].as_ref()) @@ -1222,7 +1210,7 @@ fn map_value_list() { let new_values = serialize_values_only_new(row.clone(), cols); assert_eq!( new_values, - vec![ + &[ 0, 3, // value count: 3 0, 0, 0, 4, 0, 0, 0, 1, // ala: 1 0, 0, 0, 4, 0, 0, 0, 2, // ma: 2 @@ -1251,7 +1239,7 @@ fn ref_value_list() { assert_eq!( serialized.iter().collect::>(), - vec![ + &[ RawValue::Value([0, 0, 0, 1].as_ref()), RawValue::Value([0, 0, 0, 2].as_ref()), RawValue::Value([0, 0, 0, 3].as_ref()) @@ -1343,7 +1331,7 @@ fn slice_batch_values() { col_spec("b", ColumnType::TinyInt), ]; let request = serialize_batch_value_iterators(&mut iters, cols); - assert_eq!(request, vec![0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 2]); + assert_eq!(request, &[0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 2]); } { @@ -1356,14 +1344,14 @@ fn slice_batch_values() { let request = serialize_batch_value_iterators(&mut iters, cols); assert_eq!( request, - vec![0, 4, 0, 0, 0, 1, 2, 0, 0, 0, 1, 3, 0, 0, 0, 1, 4, 0, 0, 0, 1, 5] + &[0, 4, 0, 0, 0, 1, 2, 0, 0, 0, 1, 3, 0, 0, 0, 1, 4, 0, 0, 0, 1, 5] ); } { let cols = &[col_spec("a", ColumnType::TinyInt)]; let request = serialize_batch_value_iterators(&mut iters, cols); - assert_eq!(request, vec![0, 1, 0, 0, 0, 1, 6]); + assert_eq!(request, &[0, 1, 0, 0, 0, 1, 6]); } assert_eq!(iters.0.write_next_to_request(&mut Vec::new()), None); @@ -1386,7 +1374,7 @@ fn vec_batch_values() { col_spec("b", ColumnType::TinyInt), ]; let request = serialize_batch_value_iterators(&mut iters, cols); - assert_eq!(request, vec![0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 2]); + assert_eq!(request, &[0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 2]); } { @@ -1399,14 +1387,14 @@ fn vec_batch_values() { let request = serialize_batch_value_iterators(&mut iters, cols); assert_eq!( request, - vec![0, 4, 0, 0, 0, 1, 2, 0, 0, 0, 1, 3, 0, 0, 0, 1, 4, 0, 0, 0, 1, 5] + &[0, 4, 0, 0, 0, 1, 2, 0, 0, 0, 1, 3, 0, 0, 0, 1, 4, 0, 0, 0, 1, 5] ); } { let cols = &[col_spec("a", ColumnType::TinyInt)]; let request = serialize_batch_value_iterators(&mut iters, cols); - assert_eq!(request, vec![0, 1, 0, 0, 0, 1, 6]); + assert_eq!(request, &[0, 1, 0, 0, 0, 1, 6]); } } @@ -1619,7 +1607,7 @@ fn ref_batch_values() { let mut iters = make_batch_value_iters(&batch_values, &legacy_batch_values); let request = serialize_batch_value_iterators(&mut iters, cols); - assert_eq!(request, vec![0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 2]); + assert_eq!(request, &[0, 2, 0, 0, 0, 1, 1, 0, 0, 0, 1, 2]); } } @@ -1661,7 +1649,7 @@ fn check_batch_values_iterator_is_not_lending() { let mut it = bv.batch_values_iter(); let mut it2 = bv.batch_values_iter(); // Make sure we can hold all these at the same time - let v = vec![ + let v = &[ it.next_serialized().unwrap().unwrap(), it2.next_serialized().unwrap().unwrap(), it.next_serialized().unwrap().unwrap(), @@ -1679,7 +1667,7 @@ fn check_batch_values_iterator_is_not_lending() { let mut writer = RowWriter::new(&mut data); // Make sure we can hold all these at the same time - let v = vec![ + let v = &[ it.serialize_next(&ctx, &mut writer).unwrap().unwrap(), it2.serialize_next(&ctx, &mut writer).unwrap().unwrap(), it.serialize_next(&ctx, &mut writer).unwrap().unwrap(), diff --git a/scylla-cql/src/types/deserialize/value_tests.rs b/scylla-cql/src/types/deserialize/value_tests.rs index 2ce5d0ea4..193b32d31 100644 --- a/scylla-cql/src/types/deserialize/value_tests.rs +++ b/scylla-cql/src/types/deserialize/value_tests.rs @@ -393,8 +393,8 @@ fn test_list_and_set() { assert_eq!(iter.next().transpose().unwrap(), Some("fox")); assert_eq!(iter.next().transpose().unwrap(), None); - let expected_vec_str = vec!["quick", "brown", "fox"]; - let expected_vec_string = vec!["quick".to_string(), "brown".to_string(), "fox".to_string()]; + let expected_vec_str = ["quick", "brown", "fox"]; + let expected_vec_string = ["quick".to_string(), "brown".to_string(), "fox".to_string()]; // list let decoded_vec_str = deserialize::>(&list_typ, &collection).unwrap(); @@ -483,8 +483,8 @@ fn test_map() { assert_eq!(iter.next().transpose().unwrap(), Some((3, "fox"))); assert_eq!(iter.next().transpose().unwrap(), None); - let expected_str = vec![(1, "quick"), (2, "brown"), (3, "fox")]; - let expected_string = vec![ + let expected_str = [(1, "quick"), (2, "brown"), (3, "fox")]; + let expected_string = [ (1, "quick".to_string()), (2, "brown".to_string()), (3, "fox".to_string()), diff --git a/scylla-cql/src/types/serialize/row.rs b/scylla-cql/src/types/serialize/row.rs index 3888a122b..e55b329e3 100644 --- a/scylla-cql/src/types/serialize/row.rs +++ b/scylla-cql/src/types/serialize/row.rs @@ -1026,7 +1026,7 @@ mod tests { col_spec("b", ColumnType::Int), ]; let buf = do_serialize(ValueListAdapter(Foo), columns); - let expected = vec![ + let expected = &[ 0, 0, 0, 4, 0, 0, 0, 123, // First value 0, 0, 0, 4, 0, 0, 1, 65, // Second value ]; @@ -1093,11 +1093,11 @@ mod tests { fn test_slice_errors() { // Non-unit tuple // Count mismatch - let v = vec!["Ala ma kota"]; + let v = &["Ala ma kota"][..]; let spec = [col("a", ColumnType::Text), col("b", ColumnType::Text)]; let err = do_serialize_err(v, &spec); let err = get_typeck_err(&err); - assert_eq!(err.rust_name, std::any::type_name::>()); + assert_eq!(err.rust_name, std::any::type_name::<&[&str]>()); assert_matches!( err.kind, BuiltinTypeCheckErrorKind::WrongColumnCount { @@ -1107,7 +1107,7 @@ mod tests { ); // Serialization of one of the element fails - let v = vec!["Ala ma kota", "Kot ma pchły"]; + let v = &["Ala ma kota", "Kot ma pchły"][..]; let spec = [col("a", ColumnType::Text), col("b", ColumnType::Int)]; let err = do_serialize_err(v, &spec); let err = get_ser_err(&err); diff --git a/scylla/src/transport/caching_session.rs b/scylla/src/transport/caching_session.rs index c813a6e2d..9534366c5 100644 --- a/scylla/src/transport/caching_session.rs +++ b/scylla/src/transport/caching_session.rs @@ -708,7 +708,7 @@ mod tests { .unwrap(); rows.sort_unstable(); - assert_eq!(rows, vec![(1, 1000), (2, 2000)]); + assert_eq!(rows, &[(1, 1000), (2, 2000)]); } // Checks whether the PartitionerName is cached properly. diff --git a/scylla/src/transport/cql_collections_test.rs b/scylla/src/transport/cql_collections_test.rs index f37d28a8f..ae95215c4 100644 --- a/scylla/src/transport/cql_collections_test.rs +++ b/scylla/src/transport/cql_collections_test.rs @@ -117,7 +117,7 @@ async fn test_cql_set() { .await; // HashSet - let set_hashset: HashSet = vec![-1, 1, -2].into_iter().collect(); + let set_hashset: HashSet = [-1, 1, -2].into_iter().collect(); let set_hashset_empty: HashSet = HashSet::new(); let set_hashset_empty_selected: Option> = None; insert_and_select(&session, table_name, &set_hashset, &set_hashset).await; @@ -130,7 +130,7 @@ async fn test_cql_set() { .await; // BTreeSet - let set_btreeset: BTreeSet = vec![0, -2, -1].into_iter().collect(); + let set_btreeset: BTreeSet = [0, -2, -1].into_iter().collect(); let set_btreeset_empty: BTreeSet = BTreeSet::new(); let set_btreeset_empty_selected: Option> = None; insert_and_select(&session, table_name, &set_btreeset, &set_btreeset).await; diff --git a/scylla/src/transport/cql_types_test.rs b/scylla/src/transport/cql_types_test.rs index 0a1833fd7..6009100b5 100644 --- a/scylla/src/transport/cql_types_test.rs +++ b/scylla/src/transport/cql_types_test.rs @@ -109,13 +109,13 @@ where .collect::>(); let expected_value = T::from_str(test).ok().unwrap(); - assert_eq!(read_values, vec![expected_value.clone(), expected_value]); + assert_eq!(read_values, &[expected_value.clone(), expected_value]); } } #[cfg(any(feature = "num-bigint-03", feature = "num-bigint-04"))] -fn varint_test_cases() -> Vec<&'static str> { - vec![ +fn varint_test_cases() -> &'static [&'static str] { + &[ "0", "1", "127", @@ -151,20 +151,20 @@ async fn test_varint04() { #[tokio::test] async fn test_cql_varint() { setup_tracing(); - let tests = [ - vec![0x00], // 0 - vec![0x01], // 1 - vec![0x00, 0x01], // 1 (with leading zeros) - vec![0x7F], // 127 - vec![0x00, 0x80], // 128 - vec![0x00, 0x81], // 129 - vec![0xFF], // -1 - vec![0x80], // -128 - vec![0xFF, 0x7F], // -129 - vec![ + let tests = &[ + &[0x00][..], // 0 + &[0x01], // 1 + &[0x00, 0x01], // 1 (with leading zeros) + &[0x7F], // 127 + &[0x00, 0x80], // 128 + &[0x00, 0x81], // 129 + &[0xFF], // -1 + &[0x80], // -128 + &[0xFF, 0x7F], // -129 + &[ 0x01, 0x8E, 0xE9, 0x0F, 0xF6, 0xC3, 0x73, 0xE0, 0xEE, 0x4E, 0x3F, 0x0A, 0xD2, ], // 123456789012345678901234567890 - vec![ + &[ 0xFE, 0x71, 0x16, 0xF0, 0x09, 0x3C, 0x8C, 0x1F, 0x11, 0xB1, 0xC0, 0xF5, 0x2E, ], // -123456789012345678901234567890 ]; @@ -229,7 +229,7 @@ async fn test_cql_varint() { .map(|row| row.0) .collect::>(); - assert_eq!(read_values, vec![cql_varint]) + assert_eq!(read_values, &[cql_varint]) } } @@ -308,7 +308,7 @@ async fn test_counter() { .collect::>(); let expected_value = Counter(i64::from_str(test).unwrap()); - assert_eq!(read_values, vec![expected_value]); + assert_eq!(read_values, &[expected_value]); } } @@ -1332,7 +1332,7 @@ async fn test_timeuuid_ordering() { .unwrap(); // Timeuuid values, sorted in the same order as Scylla/Cassandra sorts them. - let sorted_timeuuid_vals: Vec = vec![ + let sorted_timeuuid_vals: &[CqlTimeuuid] = &[ CqlTimeuuid::from_str("00000000-0000-1000-8080-808080808080").unwrap(), CqlTimeuuid::from_str("00000000-0000-1000-ffff-ffffffffffff").unwrap(), CqlTimeuuid::from_str("00000000-0000-1000-0000-000000000000").unwrap(), @@ -1481,27 +1481,27 @@ async fn test_blob() { setup_tracing(); let session: Session = init_test("blob_tests", "blob").await; - let long_blob: Vec = vec![0x11; 1234]; + let long_blob: &[u8] = &[0x11; 1234]; let mut long_blob_str: String = "0x".to_string(); long_blob_str.extend(std::iter::repeat('1').take(2 * 1234)); let tests = [ - ("0x", vec![]), - ("0x00", vec![0x00]), - ("0x01", vec![0x01]), - ("0xff", vec![0xff]), - ("0x1122", vec![0x11, 0x22]), - ("0x112233", vec![0x11, 0x22, 0x33]), - ("0x11223344", vec![0x11, 0x22, 0x33, 0x44]), - ("0x1122334455", vec![0x11, 0x22, 0x33, 0x44, 0x55]), - ("0x112233445566", vec![0x11, 0x22, 0x33, 0x44, 0x55, 0x66]), + ("0x", &[][..]), + ("0x00", &[0x00]), + ("0x01", &[0x01]), + ("0xff", &[0xff]), + ("0x1122", &[0x11, 0x22]), + ("0x112233", &[0x11, 0x22, 0x33]), + ("0x11223344", &[0x11, 0x22, 0x33, 0x44]), + ("0x1122334455", &[0x11, 0x22, 0x33, 0x44, 0x55]), + ("0x112233445566", &[0x11, 0x22, 0x33, 0x44, 0x55, 0x66]), ( "0x11223344556677", - vec![0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77], + &[0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77], ), ( "0x1122334455667788", - vec![0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88], + &[0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0x88], ), (&long_blob_str, long_blob), ]; diff --git a/scylla/src/transport/cql_value_test.rs b/scylla/src/transport/cql_value_test.rs index 53560ed94..57eb16778 100644 --- a/scylla/src/transport/cql_value_test.rs +++ b/scylla/src/transport/cql_value_test.rs @@ -100,12 +100,12 @@ async fn test_cqlvalue_duration() { nanoseconds: 21372137, }); - let fixture_queries = vec![ - ("CREATE TABLE IF NOT EXISTS cqlvalue_duration_test (pk int, ck int, v duration, primary key (pk, ck))", vec![],), - ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 0, ?)", vec![&duration_cql_value,],), - ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 1, 89h4m48s)", vec![],), - ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 2, PT89H8M53S)", vec![],), - ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 3, P0000-00-00T89:09:09)", vec![],), + let fixture_queries = [ + ("CREATE TABLE IF NOT EXISTS cqlvalue_duration_test (pk int, ck int, v duration, primary key (pk, ck))", &[][..],), + ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 0, ?)", &[&duration_cql_value,],), + ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 1, 89h4m48s)", &[],), + ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 2, PT89H8M53S)", &[],), + ("INSERT INTO cqlvalue_duration_test (pk, ck, v) VALUES (0, 3, P0000-00-00T89:09:09)", &[],), ]; for query in fixture_queries { diff --git a/scylla/src/transport/downgrading_consistency_retry_policy.rs b/scylla/src/transport/downgrading_consistency_retry_policy.rs index e52a44cbf..a41b82990 100644 --- a/scylla/src/transport/downgrading_consistency_retry_policy.rs +++ b/scylla/src/transport/downgrading_consistency_retry_policy.rs @@ -229,7 +229,7 @@ mod tests { #[test] fn downgrading_consistency_never_retries() { setup_tracing(); - let never_retried_dberrors = vec![ + let never_retried_dberrors = [ DbError::SyntaxError, DbError::Invalid, DbError::AlreadyExists { @@ -321,7 +321,7 @@ mod tests { #[test] fn downgrading_consistency_idempotent_next_retries() { setup_tracing(); - let idempotent_next_errors = vec![ + let idempotent_next_errors = &[ QueryError::DbError(DbError::Overloaded, String::new()), QueryError::DbError(DbError::TruncateError, String::new()), QueryError::DbError(DbError::ServerError, String::new()), diff --git a/scylla/src/transport/legacy_query_result.rs b/scylla/src/transport/legacy_query_result.rs index f1c63c719..fa5a7987a 100644 --- a/scylla/src/transport/legacy_query_result.rs +++ b/scylla/src/transport/legacy_query_result.rs @@ -372,7 +372,7 @@ mod tests { .map(|r| r.unwrap()) .collect(); - assert_eq!(rows0, vec![]); + assert_eq!(rows0, &[]); let rows1: Vec<(i32,)> = make_rows_query_result(1) .rows_typed::<(i32,)>() @@ -380,7 +380,7 @@ mod tests { .map(|r| r.unwrap()) .collect(); - assert_eq!(rows1, vec![(0,)]); + assert_eq!(rows1, &[(0,)]); let rows2: Vec<(i32,)> = make_rows_query_result(2) .rows_typed::<(i32,)>() @@ -388,7 +388,7 @@ mod tests { .map(|r| r.unwrap()) .collect(); - assert_eq!(rows2, vec![(0,), (1,)]); + assert_eq!(rows2, &[(0,), (1,)]); } #[test] @@ -412,7 +412,7 @@ mod tests { #[test] fn rows_or_empty_test() { setup_tracing(); - assert_eq!(make_not_rows_query_result().rows_or_empty(), vec![]); + assert_eq!(make_not_rows_query_result().rows_or_empty(), &[]); assert_eq!(make_rows_query_result(0).rows_or_empty(), make_rows(0)); assert_eq!(make_rows_query_result(1).rows_or_empty(), make_rows(1)); assert_eq!(make_rows_query_result(2).rows_or_empty(), make_rows(2)); @@ -426,28 +426,28 @@ mod tests { .map(|r| r.unwrap()) .collect(); - assert_eq!(rows_empty, vec![]); + assert_eq!(rows_empty, &[]); let rows0: Vec<(i32,)> = make_rows_query_result(0) .rows_typed_or_empty::<(i32,)>() .map(|r| r.unwrap()) .collect(); - assert_eq!(rows0, vec![]); + assert_eq!(rows0, &[]); let rows1: Vec<(i32,)> = make_rows_query_result(1) .rows_typed_or_empty::<(i32,)>() .map(|r| r.unwrap()) .collect(); - assert_eq!(rows1, vec![(0,)]); + assert_eq!(rows1, &[(0,)]); let rows2: Vec<(i32,)> = make_rows_query_result(2) .rows_typed_or_empty::<(i32,)>() .map(|r| r.unwrap()) .collect(); - assert_eq!(rows2, vec![(0,), (1,)]); + assert_eq!(rows2, &[(0,), (1,)]); } #[test] diff --git a/scylla/src/transport/locator/mod.rs b/scylla/src/transport/locator/mod.rs index 2ae46856d..a7e349bee 100644 --- a/scylla/src/transport/locator/mod.rs +++ b/scylla/src/transport/locator/mod.rs @@ -859,21 +859,21 @@ mod tests { None, &metadata.keyspaces.get(KEYSPACE_NTS_RF_3).unwrap().strategy, TABLE_NTS_RF_3, - vec![F, A, C, D, G, E], + &[F, A, C, D, G, E][..], ); check( 160, None, &metadata.keyspaces.get(KEYSPACE_NTS_RF_2).unwrap().strategy, TABLE_NTS_RF_2, - vec![F, A, D, G], + &[F, A, D, G], ); check( 160, None, &metadata.keyspaces.get(KEYSPACE_SS_RF_2).unwrap().strategy, TABLE_SS_RF_2, - vec![F, A], + &[F, A], ); check( @@ -881,21 +881,21 @@ mod tests { Some("eu"), &metadata.keyspaces.get(KEYSPACE_NTS_RF_3).unwrap().strategy, TABLE_NTS_RF_3, - vec![A, C, G], + &[A, C, G], ); check( 160, Some("us"), &metadata.keyspaces.get(KEYSPACE_NTS_RF_3).unwrap().strategy, TABLE_NTS_RF_3, - vec![F, D, E], + &[F, D, E], ); check( 160, Some("eu"), &metadata.keyspaces.get(KEYSPACE_SS_RF_2).unwrap().strategy, TABLE_SS_RF_2, - vec![A], + &[A], ); } } diff --git a/scylla/src/transport/locator/precomputed_replicas.rs b/scylla/src/transport/locator/precomputed_replicas.rs index 69851df50..531efb3c8 100644 --- a/scylla/src/transport/locator/precomputed_replicas.rs +++ b/scylla/src/transport/locator/precomputed_replicas.rs @@ -267,19 +267,19 @@ mod tests { assert_eq!(ids, expected_node_ids); }; - check(160, 0, vec![]); - check(160, 1, vec![F]); - check(160, 2, vec![F, A]); + check(160, 0, &[][..]); + check(160, 1, &[F]); + check(160, 2, &[F, A]); assert_eq!( precomputed_replicas.get_precomputed_simple_strategy_replicas(Token::new(160), 3), None ); - check(200, 1, vec![F]); - check(200, 2, vec![F, A]); + check(200, 1, &[F]); + check(200, 2, &[F, A]); - check(701, 1, vec![E]); - check(701, 2, vec![E, G]); + check(701, 1, &[E]); + check(701, 2, &[E, G]); } #[tokio::test] @@ -312,10 +312,10 @@ mod tests { assert_eq!(ids, expected_node_ids); }; - check(160, "eu", 0, vec![]); - check(160, "eu", 1, vec![A]); - check(160, "eu", 2, vec![A, G]); - check(160, "eu", 3, vec![A, C, G]); + check(160, "eu", 0, &[][..]); + check(160, "eu", 1, &[A]); + check(160, "eu", 2, &[A, G]); + check(160, "eu", 3, &[A, C, G]); assert_eq!( precomputed_replicas.get_precomputed_network_strategy_replicas( Token::new(160), @@ -325,10 +325,10 @@ mod tests { None ); - check(160, "us", 0, vec![]); - check(160, "us", 1, vec![F]); - check(160, "us", 2, vec![F, D]); - check(160, "us", 3, vec![F, D, E]); + check(160, "us", 0, &[][..]); + check(160, "us", 1, &[F]); + check(160, "us", 2, &[F, D]); + check(160, "us", 3, &[F, D, E]); assert_eq!( precomputed_replicas.get_precomputed_network_strategy_replicas( Token::new(160), diff --git a/scylla/src/transport/locator/replication_info.rs b/scylla/src/transport/locator/replication_info.rs index 76747abf2..c0ed6b24a 100644 --- a/scylla/src/transport/locator/replication_info.rs +++ b/scylla/src/transport/locator/replication_info.rs @@ -227,25 +227,25 @@ mod tests { assert_eq!(ids, expected_node_ids); }; - check(160, 0, vec![]); - check(160, 2, vec![F, A]); - - check(200, 1, vec![F]); - check(200, 2, vec![F, A]); - check(200, 3, vec![F, A, C]); - check(200, 4, vec![F, A, C, D]); - check(200, 5, vec![F, A, C, D, G]); - check(200, 6, vec![F, A, C, D, G, B]); - check(200, 7, vec![F, A, C, D, G, B, E]); - - check(701, 1, vec![E]); - check(701, 2, vec![E, G]); - check(701, 3, vec![E, G, B]); - check(701, 4, vec![E, G, B, A]); - check(701, 5, vec![E, G, B, A, F]); - check(701, 6, vec![E, G, B, A, F, C]); - check(701, 7, vec![E, G, B, A, F, C, D]); - check(701, 8, vec![E, G, B, A, F, C, D]); + check(160, 0, &[][..]); + check(160, 2, &[F, A]); + + check(200, 1, &[F]); + check(200, 2, &[F, A]); + check(200, 3, &[F, A, C]); + check(200, 4, &[F, A, C, D]); + check(200, 5, &[F, A, C, D, G]); + check(200, 6, &[F, A, C, D, G, B]); + check(200, 7, &[F, A, C, D, G, B, E]); + + check(701, 1, &[E]); + check(701, 2, &[E, G]); + check(701, 3, &[E, G, B]); + check(701, 4, &[E, G, B, A]); + check(701, 5, &[E, G, B, A, F]); + check(701, 6, &[E, G, B, A, F, C]); + check(701, 7, &[E, G, B, A, F, C, D]); + check(701, 8, &[E, G, B, A, F, C, D]); } #[tokio::test] @@ -261,17 +261,17 @@ mod tests { assert_eq!(ids, expected); }; - check(160, "eu", 0, vec![]); - check(160, "eu", 1, vec![A]); - check(160, "eu", 2, vec![A, G]); - check(160, "eu", 3, vec![A, C, G]); - check(160, "eu", 4, vec![A, C, G, B]); - check(160, "eu", 5, vec![A, C, G, B]); - - check(160, "us", 0, vec![]); - check(160, "us", 1, vec![F]); - check(160, "us", 2, vec![F, D]); - check(160, "us", 3, vec![F, D, E]); - check(160, "us", 4, vec![F, D, E]); + check(160, "eu", 0, &[][..]); + check(160, "eu", 1, &[A]); + check(160, "eu", 2, &[A, G]); + check(160, "eu", 3, &[A, C, G]); + check(160, "eu", 4, &[A, C, G, B]); + check(160, "eu", 5, &[A, C, G, B]); + + check(160, "us", 0, &[]); + check(160, "us", 1, &[F]); + check(160, "us", 2, &[F, D]); + check(160, "us", 3, &[F, D, E]); + check(160, "us", 4, &[F, D, E]); } } diff --git a/scylla/src/transport/locator/token_ring.rs b/scylla/src/transport/locator/token_ring.rs index b78a0d808..7d62ac085 100644 --- a/scylla/src/transport/locator/token_ring.rs +++ b/scylla/src/transport/locator/token_ring.rs @@ -93,105 +93,105 @@ mod tests { ring.ring_range(Token::new(-35)) .cloned() .collect::>(), - vec![-3, -2, -1, 0, 1, 2, 3] + &[-3, -2, -1, 0, 1, 2, 3] ); assert_eq!( ring.ring_range(Token::new(-30)) .cloned() .collect::>(), - vec![-3, -2, -1, 0, 1, 2, 3] + &[-3, -2, -1, 0, 1, 2, 3] ); assert_eq!( ring.ring_range(Token::new(-25)) .cloned() .collect::>(), - vec![-2, -1, 0, 1, 2, 3, -3] + &[-2, -1, 0, 1, 2, 3, -3] ); assert_eq!( ring.ring_range(Token::new(-20)) .cloned() .collect::>(), - vec![-2, -1, 0, 1, 2, 3, -3] + &[-2, -1, 0, 1, 2, 3, -3] ); assert_eq!( ring.ring_range(Token::new(-15)) .cloned() .collect::>(), - vec![-1, 0, 1, 2, 3, -3, -2] + &[-1, 0, 1, 2, 3, -3, -2] ); assert_eq!( ring.ring_range(Token::new(-10)) .cloned() .collect::>(), - vec![-1, 0, 1, 2, 3, -3, -2] + &[-1, 0, 1, 2, 3, -3, -2] ); assert_eq!( ring.ring_range(Token::new(-5)) .cloned() .collect::>(), - vec![0, 1, 2, 3, -3, -2, -1] + &[0, 1, 2, 3, -3, -2, -1] ); assert_eq!( ring.ring_range(Token::new(0)) .cloned() .collect::>(), - vec![0, 1, 2, 3, -3, -2, -1] + &[0, 1, 2, 3, -3, -2, -1] ); assert_eq!( ring.ring_range(Token::new(5)) .cloned() .collect::>(), - vec![1, 2, 3, -3, -2, -1, 0] + &[1, 2, 3, -3, -2, -1, 0] ); assert_eq!( ring.ring_range(Token::new(10)) .cloned() .collect::>(), - vec![1, 2, 3, -3, -2, -1, 0] + &[1, 2, 3, -3, -2, -1, 0] ); assert_eq!( ring.ring_range(Token::new(15)) .cloned() .collect::>(), - vec![2, 3, -3, -2, -1, 0, 1] + &[2, 3, -3, -2, -1, 0, 1] ); assert_eq!( ring.ring_range(Token::new(20)) .cloned() .collect::>(), - vec![2, 3, -3, -2, -1, 0, 1] + &[2, 3, -3, -2, -1, 0, 1] ); assert_eq!( ring.ring_range(Token::new(25)) .cloned() .collect::>(), - vec![3, -3, -2, -1, 0, 1, 2] + &[3, -3, -2, -1, 0, 1, 2] ); assert_eq!( ring.ring_range(Token::new(30)) .cloned() .collect::>(), - vec![3, -3, -2, -1, 0, 1, 2] + &[3, -3, -2, -1, 0, 1, 2] ); assert_eq!( ring.ring_range(Token::new(35)) .cloned() .collect::>(), - vec![-3, -2, -1, 0, 1, 2, 3] + &[-3, -2, -1, 0, 1, 2, 3] ); } } diff --git a/scylla/src/transport/retry_policy.rs b/scylla/src/transport/retry_policy.rs index 54f87380e..2e937a8c2 100644 --- a/scylla/src/transport/retry_policy.rs +++ b/scylla/src/transport/retry_policy.rs @@ -237,7 +237,7 @@ mod tests { #[test] fn default_never_retries() { setup_tracing(); - let never_retried_dberrors = vec![ + let never_retried_dberrors = [ DbError::SyntaxError, DbError::Invalid, DbError::AlreadyExists { @@ -303,7 +303,7 @@ mod tests { #[test] fn default_idempotent_next_retries() { setup_tracing(); - let idempotent_next_errors = vec![ + let idempotent_next_errors = [ QueryError::DbError(DbError::Overloaded, String::new()), QueryError::DbError(DbError::TruncateError, String::new()), QueryError::DbError(DbError::ServerError, String::new()), diff --git a/scylla/src/transport/session_builder.rs b/scylla/src/transport/session_builder.rs index 31b653a5c..c9b63542f 100644 --- a/scylla/src/transport/session_builder.rs +++ b/scylla/src/transport/session_builder.rs @@ -1057,7 +1057,7 @@ mod tests { assert_eq!( builder.config.known_nodes, - vec![KnownNode::Hostname("test_hostname".into())] + &[KnownNode::Hostname("test_hostname".into())] ); assert_eq!(builder.config.compression, None); } @@ -1070,7 +1070,7 @@ mod tests { let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(172, 17, 0, 3)), 1357); builder = builder.known_node_addr(addr); - assert_eq!(builder.config.known_nodes, vec![KnownNode::Address(addr)]); + assert_eq!(builder.config.known_nodes, &[KnownNode::Address(addr)]); assert_eq!(builder.config.compression, None); } @@ -1083,7 +1083,7 @@ mod tests { assert_eq!( builder.config.known_nodes, - vec![ + &[ KnownNode::Hostname("test_hostname1".into()), KnownNode::Hostname("test_hostname2".into()) ] @@ -1103,7 +1103,7 @@ mod tests { assert_eq!( builder.config.known_nodes, - vec![KnownNode::Address(addr1), KnownNode::Address(addr2)] + &[KnownNode::Address(addr1), KnownNode::Address(addr2)] ); assert_eq!(builder.config.compression, None); } @@ -1274,7 +1274,7 @@ mod tests { assert_eq!( builder.config.known_nodes, - vec![ + &[ KnownNode::Hostname("hostname_test".into()), KnownNode::Address(addr), KnownNode::Hostname("hostname_test1".into()), diff --git a/scylla/src/transport/session_test.rs b/scylla/src/transport/session_test.rs index bde64faaf..945088bf5 100644 --- a/scylla/src/transport/session_test.rs +++ b/scylla/src/transport/session_test.rs @@ -126,7 +126,7 @@ async fn test_unprepared_statement() { results.sort(); assert_eq!( results, - vec![ + &[ (1, 2, String::from("abc")), (1, 4, String::from("hello")), (7, 11, String::from("")) @@ -518,7 +518,7 @@ async fn test_batch() { results.sort(); assert_eq!( results, - vec![ + &[ (1, 2, String::from("abc")), (1, 4, String::from("hello")), (7, 11, String::from("")) @@ -555,7 +555,7 @@ async fn test_batch() { .collect::>() .unwrap(); - assert_eq!(results, vec![(4, 20, String::from("foobar"))]); + assert_eq!(results, &[(4, 20, String::from("foobar"))]); } #[tokio::test] @@ -653,7 +653,7 @@ async fn test_token_awareness() { // The default policy should be token aware for size in 1..50usize { - let key = vec!['a'; size].into_iter().collect::(); + let key = std::iter::repeat('a').take(size).collect::(); let values = (&key,); // Execute a query and observe tracing info @@ -724,7 +724,7 @@ async fn test_use_keyspace() { rows.sort(); - assert_eq!(rows, vec!["test1".to_string(), "test2".to_string()]); + assert_eq!(rows, &["test1".to_string(), "test2".to_string()]); // Test that trying to use nonexisting keyspace fails assert!(session @@ -776,7 +776,7 @@ async fn test_use_keyspace() { rows2.sort(); - assert_eq!(rows2, vec!["test1".to_string(), "test2".to_string()]); + assert_eq!(rows2, &["test1".to_string(), "test2".to_string()]); } #[tokio::test] @@ -837,7 +837,7 @@ async fn test_use_keyspace_case_sensitivity() { .map(|row| row.unwrap().0) .collect(); - assert_eq!(rows, vec!["lowercase".to_string()]); + assert_eq!(rows, &["lowercase"]); // Use uppercase keyspace with case sensitivity // Should select the uppercase one @@ -855,7 +855,7 @@ async fn test_use_keyspace_case_sensitivity() { .map(|row| row.unwrap().0) .collect(); - assert_eq!(rows, vec!["uppercase".to_string()]); + assert_eq!(rows, &["uppercase"]); } #[tokio::test] @@ -899,7 +899,7 @@ async fn test_raw_use_keyspace() { .map(|res| res.unwrap().0) .collect(); - assert_eq!(rows, vec!["raw_test".to_string()]); + assert_eq!(rows, &["raw_test"]); // Check if case sensitivity is correctly detected assert!(session @@ -1575,14 +1575,14 @@ async fn test_schema_types_in_metadata() { assert_eq!( tables.keys().sorted().collect::>(), - vec!["table_a", "table_b"] + &["table_a", "table_b"] ); let table_a_columns = &tables["table_a"].columns; assert_eq!( table_a_columns.keys().sorted().collect::>(), - vec!["a", "b", "c", "d", "e"] + &["a", "b", "c", "d", "e"] ); let a = &table_a_columns["a"]; @@ -1709,7 +1709,7 @@ async fn test_user_defined_types_in_metadata() { assert_eq!( user_defined_types.keys().sorted().collect::>(), - vec!["type_a", "type_b", "type_c"] + &["type_a", "type_b", "type_c"] ); let type_a = &user_defined_types["type_a"]; @@ -1812,8 +1812,8 @@ async fn test_primary_key_ordering_in_metadata() { let cluster_data = session.get_cluster_data(); let table = &cluster_data.get_keyspace_info()[&ks].tables["t"]; - assert_eq!(table.partition_key, vec!["c", "e"]); - assert_eq!(table.clustering_key, vec!["b", "a"]); + assert_eq!(table.partition_key, &["c", "e"]); + assert_eq!(table.clustering_key, &["b", "a"]); } #[tokio::test] @@ -1990,9 +1990,9 @@ async fn test_named_bind_markers() { .map(|res| res.unwrap()) .collect(); - assert_eq!(rows, vec![(7, 13, 42), (17, 113, 142)]); + assert_eq!(rows, &[(7, 13, 42), (17, 113, 142)]); - let wrongmaps: Vec> = vec![ + let wrongmaps: &[HashMap<&str, i32>] = &[ HashMap::from([("pk", 7), ("fefe", 42), ("ck", 13)]), HashMap::from([("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 7)]), HashMap::new(), @@ -2144,7 +2144,7 @@ async fn test_unprepared_reprepare_in_execute() { .map(|r| r.unwrap()) .collect(); all_rows.sort_unstable(); - assert_eq!(all_rows, vec![(1, 2, 3), (1, 3, 2)]); + assert_eq!(all_rows, &[(1, 2, 3), (1, 3, 2)]); } #[tokio::test] @@ -2170,7 +2170,7 @@ async fn test_unusual_valuelists() { .await .unwrap(); - let values_dyn: Vec<&dyn SerializeValue> = vec![ + let values_dyn: &[&dyn SerializeValue] = &[ &1 as &dyn SerializeValue, &2 as &dyn SerializeValue, &"&dyn" as &dyn SerializeValue, @@ -2180,7 +2180,7 @@ async fn test_unusual_valuelists() { .await .unwrap(); - let values_box_dyn: Vec> = vec![ + let values_box_dyn: &[Box] = &[ Box::new(1) as Box, Box::new(3) as Box, Box::new("Box dyn") as Box, @@ -2204,7 +2204,7 @@ async fn test_unusual_valuelists() { all_rows.sort(); assert_eq!( all_rows, - vec![ + &[ (1i32, 2i32, "&dyn".to_owned()), (1, 3, "Box dyn".to_owned()) ] @@ -2276,7 +2276,7 @@ async fn test_unprepared_reprepare_in_batch() { .map(|r| r.unwrap()) .collect(); all_rows.sort_unstable(); - assert_eq!(all_rows, vec![(1, 2, 3), (1, 3, 2), (4, 5, 6), (4, 6, 5)]); + assert_eq!(all_rows, &[(1, 2, 3), (1, 3, 2), (4, 5, 6), (4, 6, 5)]); } // A tests which checks that Session::execute automatically reprepares PreparedStatemtns if they become unprepared. @@ -2346,7 +2346,7 @@ async fn test_unprepared_reprepare_in_caching_session_execute() { .map(|r| r.unwrap()) .collect(); all_rows.sort_unstable(); - assert_eq!(all_rows, vec![(1, 2, 3), (1, 3, 2)]); + assert_eq!(all_rows, &[(1, 2, 3), (1, 3, 2)]); } #[tokio::test] @@ -2667,7 +2667,7 @@ async fn test_batch_lwts_for_scylla( .collect::>() .unwrap(); - let expected_batch_res_rows = vec![ + let expected_batch_res_rows = &[ (true, Some(0), Some(0), Some(0), Some(0)), (true, None, None, None, None), (true, Some(0), Some(0), Some(0), Some(0)), @@ -2689,7 +2689,7 @@ async fn test_batch_lwts_for_scylla( .map(|r| r.unwrap()) .collect(); - let expected_prepared_batch_res_rows = vec![ + let expected_prepared_batch_res_rows = &[ (false, Some(0), Some(0), Some(1), Some(1)), (false, None, None, None, None), (false, Some(0), Some(0), Some(1), Some(1)), @@ -2714,7 +2714,7 @@ async fn test_batch_lwts_for_cassandra( .map(|r| r.unwrap()) .collect(); - let expected_batch_res_rows = vec![(true,)]; + let expected_batch_res_rows = &[(true,)]; assert_eq!(batch_res_rows, expected_batch_res_rows); @@ -2734,7 +2734,7 @@ async fn test_batch_lwts_for_cassandra( .map(|r| r.unwrap()) .collect(); - let expected_prepared_batch_res_rows = vec![(false, Some(0), Some(0), Some(1), Some(1))]; + let expected_prepared_batch_res_rows = &[(false, Some(0), Some(0), Some(1), Some(1))]; assert_eq!(prepared_batch_res_rows, expected_prepared_batch_res_rows); } @@ -2992,7 +2992,7 @@ async fn simple_strategy_test() { .collect::>(); rows.sort(); - assert_eq!(rows, vec![(1, 2, 3), (4, 5, 6), (7, 8, 9)]); + assert_eq!(rows, &[(1, 2, 3), (4, 5, 6), (7, 8, 9)]); } #[tokio::test]