Skip to content

Commit cd63ce3

Browse files
authored
Merge pull request #211 from muzarski/clippy-1.83
2 parents 08bc6a5 + bd9047f commit cd63ce3

File tree

6 files changed

+104
-84
lines changed

6 files changed

+104
-84
lines changed

scylla-rust-wrapper/src/cluster.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,6 +1070,8 @@ mod tests {
10701070
);
10711071

10721072
// empty strings
1073+
// Allow it, since c"" somehow clashes with #[ntest] proc macro...
1074+
#[allow(clippy::manual_c_str_literals)]
10731075
let empty_str = "\0".as_ptr() as *const i8;
10741076
assert_cass_error_eq!(
10751077
cass_cluster_set_load_balance_dc_aware(cluster_raw, std::ptr::null(), 0, 0),

scylla-rust-wrapper/src/exec_profile.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,7 @@ mod tests {
528528
assert_cass_error_eq!(
529529
cass_execution_profile_set_load_balance_dc_aware(
530530
profile_raw,
531-
"eu\0".as_ptr() as *const i8,
531+
c"eu".as_ptr(),
532532
0,
533533
0
534534
),
@@ -562,7 +562,7 @@ mod tests {
562562
assert_cass_error_eq!(
563563
cass_execution_profile_set_load_balance_dc_aware(
564564
profile_raw,
565-
"eu\0".as_ptr() as *const i8,
565+
c"eu".as_ptr(),
566566
1,
567567
0
568568
),
@@ -571,7 +571,7 @@ mod tests {
571571
assert_cass_error_eq!(
572572
cass_execution_profile_set_load_balance_dc_aware(
573573
profile_raw,
574-
"eu\0".as_ptr() as *const i8,
574+
c"eu".as_ptr(),
575575
0,
576576
1
577577
),

scylla-rust-wrapper/src/external.rs

Lines changed: 62 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,74 +4,74 @@ use std::os::raw::c_char;
44
#[no_mangle]
55
pub unsafe extern "C" fn cass_error_desc(error: CassError) -> *const c_char {
66
let desc = match error {
7-
CassError::CASS_ERROR_LIB_BAD_PARAMS => "Bad parameters\0",
8-
CassError::CASS_ERROR_LIB_NO_STREAMS => "No streams available\0",
9-
CassError::CASS_ERROR_LIB_UNABLE_TO_INIT => "Unable to initialize\0",
10-
CassError::CASS_ERROR_LIB_MESSAGE_ENCODE => "Unable to encode message\0",
11-
CassError::CASS_ERROR_LIB_HOST_RESOLUTION => "Unable to resolve host\0",
12-
CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE => "Unexpected response from server\0",
13-
CassError::CASS_ERROR_LIB_REQUEST_QUEUE_FULL => "The request queue is full\0",
14-
CassError::CASS_ERROR_LIB_NO_AVAILABLE_IO_THREAD => "No available IO threads\0",
15-
CassError::CASS_ERROR_LIB_WRITE_ERROR => "Write error\0",
16-
CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE => "No hosts available\0",
17-
CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS => "Index out of bounds\0",
18-
CassError::CASS_ERROR_LIB_INVALID_ITEM_COUNT => "Invalid item count\0",
19-
CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE => "Invalid value type\0",
20-
CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT => "Request timed out\0",
21-
CassError::CASS_ERROR_LIB_UNABLE_TO_SET_KEYSPACE => "Unable to set keyspace\0",
22-
CassError::CASS_ERROR_LIB_CALLBACK_ALREADY_SET => "Callback already set\0",
23-
CassError::CASS_ERROR_LIB_INVALID_STATEMENT_TYPE => "Invalid statement type\0",
24-
CassError::CASS_ERROR_LIB_NAME_DOES_NOT_EXIST => "No value or column for name\0",
7+
CassError::CASS_ERROR_LIB_BAD_PARAMS => c"Bad parameters",
8+
CassError::CASS_ERROR_LIB_NO_STREAMS => c"No streams available",
9+
CassError::CASS_ERROR_LIB_UNABLE_TO_INIT => c"Unable to initialize",
10+
CassError::CASS_ERROR_LIB_MESSAGE_ENCODE => c"Unable to encode message",
11+
CassError::CASS_ERROR_LIB_HOST_RESOLUTION => c"Unable to resolve host",
12+
CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE => c"Unexpected response from server",
13+
CassError::CASS_ERROR_LIB_REQUEST_QUEUE_FULL => c"The request queue is full",
14+
CassError::CASS_ERROR_LIB_NO_AVAILABLE_IO_THREAD => c"No available IO threads",
15+
CassError::CASS_ERROR_LIB_WRITE_ERROR => c"Write error",
16+
CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE => c"No hosts available",
17+
CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS => c"Index out of bounds",
18+
CassError::CASS_ERROR_LIB_INVALID_ITEM_COUNT => c"Invalid item count",
19+
CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE => c"Invalid value type",
20+
CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT => c"Request timed out",
21+
CassError::CASS_ERROR_LIB_UNABLE_TO_SET_KEYSPACE => c"Unable to set keyspace",
22+
CassError::CASS_ERROR_LIB_CALLBACK_ALREADY_SET => c"Callback already set",
23+
CassError::CASS_ERROR_LIB_INVALID_STATEMENT_TYPE => c"Invalid statement type",
24+
CassError::CASS_ERROR_LIB_NAME_DOES_NOT_EXIST => c"No value or column for name",
2525
CassError::CASS_ERROR_LIB_UNABLE_TO_DETERMINE_PROTOCOL => {
26-
"Unable to find supported protocol version\0"
26+
c"Unable to find supported protocol version"
2727
}
28-
CassError::CASS_ERROR_LIB_NULL_VALUE => "NULL value specified\0",
29-
CassError::CASS_ERROR_LIB_NOT_IMPLEMENTED => "Not implemented\0",
30-
CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT => "Unable to connect\0",
31-
CassError::CASS_ERROR_LIB_UNABLE_TO_CLOSE => "Unable to close\0",
32-
CassError::CASS_ERROR_LIB_NO_PAGING_STATE => "No paging state\0",
33-
CassError::CASS_ERROR_LIB_PARAMETER_UNSET => "Parameter unset\0",
34-
CassError::CASS_ERROR_LIB_INVALID_ERROR_RESULT_TYPE => "Invalid error result type\0",
35-
CassError::CASS_ERROR_LIB_INVALID_FUTURE_TYPE => "Invalid future type\0",
36-
CassError::CASS_ERROR_LIB_INTERNAL_ERROR => "Internal error\0",
37-
CassError::CASS_ERROR_LIB_INVALID_CUSTOM_TYPE => "Invalid custom type\0",
38-
CassError::CASS_ERROR_LIB_INVALID_DATA => "Invalid data\0",
39-
CassError::CASS_ERROR_LIB_NOT_ENOUGH_DATA => "Not enough data\0",
40-
CassError::CASS_ERROR_LIB_INVALID_STATE => "Invalid state\0",
41-
CassError::CASS_ERROR_LIB_NO_CUSTOM_PAYLOAD => "No custom payload\0",
28+
CassError::CASS_ERROR_LIB_NULL_VALUE => c"NULL value specified",
29+
CassError::CASS_ERROR_LIB_NOT_IMPLEMENTED => c"Not implemented",
30+
CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT => c"Unable to connect",
31+
CassError::CASS_ERROR_LIB_UNABLE_TO_CLOSE => c"Unable to close",
32+
CassError::CASS_ERROR_LIB_NO_PAGING_STATE => c"No paging state",
33+
CassError::CASS_ERROR_LIB_PARAMETER_UNSET => c"Parameter unset",
34+
CassError::CASS_ERROR_LIB_INVALID_ERROR_RESULT_TYPE => c"Invalid error result type",
35+
CassError::CASS_ERROR_LIB_INVALID_FUTURE_TYPE => c"Invalid future type",
36+
CassError::CASS_ERROR_LIB_INTERNAL_ERROR => c"Internal error",
37+
CassError::CASS_ERROR_LIB_INVALID_CUSTOM_TYPE => c"Invalid custom type",
38+
CassError::CASS_ERROR_LIB_INVALID_DATA => c"Invalid data",
39+
CassError::CASS_ERROR_LIB_NOT_ENOUGH_DATA => c"Not enough data",
40+
CassError::CASS_ERROR_LIB_INVALID_STATE => c"Invalid state",
41+
CassError::CASS_ERROR_LIB_NO_CUSTOM_PAYLOAD => c"No custom payload",
4242
CassError::CASS_ERROR_LIB_EXECUTION_PROFILE_INVALID => {
43-
"Invalid execution profile specified\0"
43+
c"Invalid execution profile specified"
4444
}
45-
CassError::CASS_ERROR_LIB_NO_TRACING_ID => "No tracing ID\0",
46-
CassError::CASS_ERROR_SERVER_SERVER_ERROR => "Server error\0",
47-
CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR => "Protocol error\0",
48-
CassError::CASS_ERROR_SERVER_BAD_CREDENTIALS => "Bad credentials\0",
49-
CassError::CASS_ERROR_SERVER_UNAVAILABLE => "Unavailable\0",
50-
CassError::CASS_ERROR_SERVER_OVERLOADED => "Overloaded\0",
51-
CassError::CASS_ERROR_SERVER_IS_BOOTSTRAPPING => "Is bootstrapping\0",
52-
CassError::CASS_ERROR_SERVER_TRUNCATE_ERROR => "Truncate error\0",
53-
CassError::CASS_ERROR_SERVER_WRITE_TIMEOUT => "Write timeout\0",
54-
CassError::CASS_ERROR_SERVER_READ_TIMEOUT => "Read timeout\0",
55-
CassError::CASS_ERROR_SERVER_READ_FAILURE => "Read failure\0",
56-
CassError::CASS_ERROR_SERVER_FUNCTION_FAILURE => "Function failure\0",
57-
CassError::CASS_ERROR_SERVER_WRITE_FAILURE => "Write failure\0",
58-
CassError::CASS_ERROR_SERVER_SYNTAX_ERROR => "Syntax error\0",
59-
CassError::CASS_ERROR_SERVER_UNAUTHORIZED => "Unauthorized\0",
60-
CassError::CASS_ERROR_SERVER_INVALID_QUERY => "Invalid query\0",
61-
CassError::CASS_ERROR_SERVER_CONFIG_ERROR => "Configuration error\0",
62-
CassError::CASS_ERROR_SERVER_ALREADY_EXISTS => "Already exists\0",
63-
CassError::CASS_ERROR_SERVER_UNPREPARED => "Unprepared\0",
64-
CassError::CASS_ERROR_SSL_INVALID_CERT => "Unable to load certificate\0",
65-
CassError::CASS_ERROR_SSL_INVALID_PRIVATE_KEY => "Unable to load private key\0",
66-
CassError::CASS_ERROR_SSL_NO_PEER_CERT => "No peer certificate\0",
67-
CassError::CASS_ERROR_SSL_INVALID_PEER_CERT => "Invalid peer certificate\0",
45+
CassError::CASS_ERROR_LIB_NO_TRACING_ID => c"No tracing ID",
46+
CassError::CASS_ERROR_SERVER_SERVER_ERROR => c"Server error",
47+
CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR => c"Protocol error",
48+
CassError::CASS_ERROR_SERVER_BAD_CREDENTIALS => c"Bad credentials",
49+
CassError::CASS_ERROR_SERVER_UNAVAILABLE => c"Unavailable",
50+
CassError::CASS_ERROR_SERVER_OVERLOADED => c"Overloaded",
51+
CassError::CASS_ERROR_SERVER_IS_BOOTSTRAPPING => c"Is bootstrapping",
52+
CassError::CASS_ERROR_SERVER_TRUNCATE_ERROR => c"Truncate error",
53+
CassError::CASS_ERROR_SERVER_WRITE_TIMEOUT => c"Write timeout",
54+
CassError::CASS_ERROR_SERVER_READ_TIMEOUT => c"Read timeout",
55+
CassError::CASS_ERROR_SERVER_READ_FAILURE => c"Read failure",
56+
CassError::CASS_ERROR_SERVER_FUNCTION_FAILURE => c"Function failure",
57+
CassError::CASS_ERROR_SERVER_WRITE_FAILURE => c"Write failure",
58+
CassError::CASS_ERROR_SERVER_SYNTAX_ERROR => c"Syntax error",
59+
CassError::CASS_ERROR_SERVER_UNAUTHORIZED => c"Unauthorized",
60+
CassError::CASS_ERROR_SERVER_INVALID_QUERY => c"Invalid query",
61+
CassError::CASS_ERROR_SERVER_CONFIG_ERROR => c"Configuration error",
62+
CassError::CASS_ERROR_SERVER_ALREADY_EXISTS => c"Already exists",
63+
CassError::CASS_ERROR_SERVER_UNPREPARED => c"Unprepared",
64+
CassError::CASS_ERROR_SSL_INVALID_CERT => c"Unable to load certificate",
65+
CassError::CASS_ERROR_SSL_INVALID_PRIVATE_KEY => c"Unable to load private key",
66+
CassError::CASS_ERROR_SSL_NO_PEER_CERT => c"No peer certificate",
67+
CassError::CASS_ERROR_SSL_INVALID_PEER_CERT => c"Invalid peer certificate",
6868
CassError::CASS_ERROR_SSL_IDENTITY_MISMATCH => {
69-
"Certificate does not match host or IP address\0"
69+
c"Certificate does not match host or IP address"
7070
}
71-
CassError::CASS_ERROR_SSL_PROTOCOL_ERROR => "Protocol error\0",
72-
CassError::CASS_ERROR_SSL_CLOSED => "Connection closed\0",
73-
_ => "\0",
71+
CassError::CASS_ERROR_SSL_PROTOCOL_ERROR => c"Protocol error",
72+
CassError::CASS_ERROR_SSL_CLOSED => c"Connection closed",
73+
_ => c"",
7474
};
7575

76-
desc.as_ptr() as *const c_char
76+
desc.as_ptr()
7777
}

scylla-rust-wrapper/src/inet.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::argconv::*;
22
use crate::cass_error::CassError;
33
use crate::types::*;
4-
use num_derive::FromPrimitive;
54
use num_traits::FromPrimitive;
65
use std::convert::TryFrom;
76
use std::convert::TryInto;
@@ -14,12 +13,33 @@ pub(crate) use crate::cass_inet_types::CassInet;
1413

1514
#[repr(u8)] // address_length field in CassInet is cass_uint8_t
1615
#[allow(non_camel_case_types)]
17-
#[derive(Debug, Copy, Clone, FromPrimitive)]
16+
#[derive(Debug, Copy, Clone)]
1817
pub enum CassInetLength {
1918
CASS_INET_V4 = 4,
2019
CASS_INET_V6 = 16,
2120
}
2221

22+
// Need to implement manually, because of the clippy 0.1.83 lints:
23+
// | `FromPrimitive` is not local
24+
// | move the `impl` block outside of this constant `_IMPL_NUM_FromPrimitive_FOR_CassInetLength`
25+
impl FromPrimitive for CassInetLength {
26+
fn from_i64(n: i64) -> Option<Self> {
27+
match n {
28+
4 => Some(Self::CASS_INET_V4),
29+
16 => Some(Self::CASS_INET_V6),
30+
_ => None,
31+
}
32+
}
33+
34+
fn from_u64(n: u64) -> Option<Self> {
35+
match n {
36+
4 => Some(Self::CASS_INET_V4),
37+
16 => Some(Self::CASS_INET_V6),
38+
_ => None,
39+
}
40+
}
41+
}
42+
2343
unsafe fn cass_inet_init(address: *const cass_uint8_t, address_length: CassInetLength) -> CassInet {
2444
let mut array = [0; 16];
2545
let length = address_length as usize;

scylla-rust-wrapper/src/logging.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ where
113113
severity: (*event.metadata().level()).into(),
114114
file: target.as_ptr() as *const c_char,
115115
line: event.metadata().line().unwrap_or(0) as i32,
116-
function: "\0".as_ptr() as *const c_char, // ignored, as cannot be fetched from event metadata
116+
function: c"".as_ptr() as *const c_char, // ignored, as cannot be fetched from event metadata
117117
message: str_to_arr(message),
118118
};
119119

@@ -167,17 +167,17 @@ pub unsafe extern "C" fn cass_log_set_level(log_level: CassLogLevel) {
167167
#[no_mangle]
168168
pub unsafe extern "C" fn cass_log_level_string(log_level: CassLogLevel) -> *const c_char {
169169
let log_level_str = match log_level {
170-
CassLogLevel::CASS_LOG_TRACE => "TRACE\0",
171-
CassLogLevel::CASS_LOG_DEBUG => "DEBUG\0",
172-
CassLogLevel::CASS_LOG_INFO => "INFO\0",
173-
CassLogLevel::CASS_LOG_WARN => "WARN\0",
174-
CassLogLevel::CASS_LOG_ERROR => "ERROR\0",
175-
CassLogLevel::CASS_LOG_CRITICAL => "CRITICAL\0",
176-
CassLogLevel::CASS_LOG_DISABLED => "DISABLED\0",
177-
_ => "\0",
170+
CassLogLevel::CASS_LOG_TRACE => c"TRACE",
171+
CassLogLevel::CASS_LOG_DEBUG => c"DEBUG",
172+
CassLogLevel::CASS_LOG_INFO => c"INFO",
173+
CassLogLevel::CASS_LOG_WARN => c"WARN",
174+
CassLogLevel::CASS_LOG_ERROR => c"ERROR",
175+
CassLogLevel::CASS_LOG_CRITICAL => c"CRITICAL",
176+
CassLogLevel::CASS_LOG_DISABLED => c"DISABLED",
177+
_ => c"",
178178
};
179179

180-
log_level_str.as_ptr() as *const c_char
180+
log_level_str.as_ptr()
181181
}
182182

183183
#[no_mangle]

scylla-rust-wrapper/src/query_result.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ pub unsafe extern "C" fn cass_row_get_column_by_name_n(
11061106
is_case_sensitive = true;
11071107
}
11081108

1109-
return row_from_raw
1109+
row_from_raw
11101110
.result_metadata
11111111
.col_specs
11121112
.iter()
@@ -1115,13 +1115,11 @@ pub unsafe extern "C" fn cass_row_get_column_by_name_n(
11151115
is_case_sensitive && col_spec.name == name_str
11161116
|| !is_case_sensitive && col_spec.name.eq_ignore_ascii_case(name_str)
11171117
})
1118-
.map(|(index, _)| {
1119-
return match row_from_raw.columns.get(index) {
1120-
Some(value) => value as *const CassValue,
1121-
None => std::ptr::null(),
1122-
};
1118+
.map(|(index, _)| match row_from_raw.columns.get(index) {
1119+
Some(value) => value as *const CassValue,
1120+
None => std::ptr::null(),
11231121
})
1124-
.unwrap_or(std::ptr::null());
1122+
.unwrap_or(std::ptr::null())
11251123
}
11261124

11271125
#[no_mangle]

0 commit comments

Comments
 (0)