diff --git a/scylla-rust-wrapper/src/cluster.rs b/scylla-rust-wrapper/src/cluster.rs index c01d172c..ea2d500c 100644 --- a/scylla-rust-wrapper/src/cluster.rs +++ b/scylla-rust-wrapper/src/cluster.rs @@ -1070,6 +1070,8 @@ mod tests { ); // empty strings + // Allow it, since c"" somehow clashes with #[ntest] proc macro... + #[allow(clippy::manual_c_str_literals)] let empty_str = "\0".as_ptr() as *const i8; assert_cass_error_eq!( cass_cluster_set_load_balance_dc_aware(cluster_raw, std::ptr::null(), 0, 0), diff --git a/scylla-rust-wrapper/src/exec_profile.rs b/scylla-rust-wrapper/src/exec_profile.rs index 6ccd2056..79cc46a0 100644 --- a/scylla-rust-wrapper/src/exec_profile.rs +++ b/scylla-rust-wrapper/src/exec_profile.rs @@ -528,7 +528,7 @@ mod tests { assert_cass_error_eq!( cass_execution_profile_set_load_balance_dc_aware( profile_raw, - "eu\0".as_ptr() as *const i8, + c"eu".as_ptr(), 0, 0 ), @@ -562,7 +562,7 @@ mod tests { assert_cass_error_eq!( cass_execution_profile_set_load_balance_dc_aware( profile_raw, - "eu\0".as_ptr() as *const i8, + c"eu".as_ptr(), 1, 0 ), @@ -571,7 +571,7 @@ mod tests { assert_cass_error_eq!( cass_execution_profile_set_load_balance_dc_aware( profile_raw, - "eu\0".as_ptr() as *const i8, + c"eu".as_ptr(), 0, 1 ), diff --git a/scylla-rust-wrapper/src/external.rs b/scylla-rust-wrapper/src/external.rs index 1c8c8fd0..2d8b68a9 100644 --- a/scylla-rust-wrapper/src/external.rs +++ b/scylla-rust-wrapper/src/external.rs @@ -4,74 +4,74 @@ use std::os::raw::c_char; #[no_mangle] pub unsafe extern "C" fn cass_error_desc(error: CassError) -> *const c_char { let desc = match error { - CassError::CASS_ERROR_LIB_BAD_PARAMS => "Bad parameters\0", - CassError::CASS_ERROR_LIB_NO_STREAMS => "No streams available\0", - CassError::CASS_ERROR_LIB_UNABLE_TO_INIT => "Unable to initialize\0", - CassError::CASS_ERROR_LIB_MESSAGE_ENCODE => "Unable to encode message\0", - CassError::CASS_ERROR_LIB_HOST_RESOLUTION => "Unable to resolve host\0", - CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE => "Unexpected response from server\0", - CassError::CASS_ERROR_LIB_REQUEST_QUEUE_FULL => "The request queue is full\0", - CassError::CASS_ERROR_LIB_NO_AVAILABLE_IO_THREAD => "No available IO threads\0", - CassError::CASS_ERROR_LIB_WRITE_ERROR => "Write error\0", - CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE => "No hosts available\0", - CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS => "Index out of bounds\0", - CassError::CASS_ERROR_LIB_INVALID_ITEM_COUNT => "Invalid item count\0", - CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE => "Invalid value type\0", - CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT => "Request timed out\0", - CassError::CASS_ERROR_LIB_UNABLE_TO_SET_KEYSPACE => "Unable to set keyspace\0", - CassError::CASS_ERROR_LIB_CALLBACK_ALREADY_SET => "Callback already set\0", - CassError::CASS_ERROR_LIB_INVALID_STATEMENT_TYPE => "Invalid statement type\0", - CassError::CASS_ERROR_LIB_NAME_DOES_NOT_EXIST => "No value or column for name\0", + CassError::CASS_ERROR_LIB_BAD_PARAMS => c"Bad parameters", + CassError::CASS_ERROR_LIB_NO_STREAMS => c"No streams available", + CassError::CASS_ERROR_LIB_UNABLE_TO_INIT => c"Unable to initialize", + CassError::CASS_ERROR_LIB_MESSAGE_ENCODE => c"Unable to encode message", + CassError::CASS_ERROR_LIB_HOST_RESOLUTION => c"Unable to resolve host", + CassError::CASS_ERROR_LIB_UNEXPECTED_RESPONSE => c"Unexpected response from server", + CassError::CASS_ERROR_LIB_REQUEST_QUEUE_FULL => c"The request queue is full", + CassError::CASS_ERROR_LIB_NO_AVAILABLE_IO_THREAD => c"No available IO threads", + CassError::CASS_ERROR_LIB_WRITE_ERROR => c"Write error", + CassError::CASS_ERROR_LIB_NO_HOSTS_AVAILABLE => c"No hosts available", + CassError::CASS_ERROR_LIB_INDEX_OUT_OF_BOUNDS => c"Index out of bounds", + CassError::CASS_ERROR_LIB_INVALID_ITEM_COUNT => c"Invalid item count", + CassError::CASS_ERROR_LIB_INVALID_VALUE_TYPE => c"Invalid value type", + CassError::CASS_ERROR_LIB_REQUEST_TIMED_OUT => c"Request timed out", + CassError::CASS_ERROR_LIB_UNABLE_TO_SET_KEYSPACE => c"Unable to set keyspace", + CassError::CASS_ERROR_LIB_CALLBACK_ALREADY_SET => c"Callback already set", + CassError::CASS_ERROR_LIB_INVALID_STATEMENT_TYPE => c"Invalid statement type", + CassError::CASS_ERROR_LIB_NAME_DOES_NOT_EXIST => c"No value or column for name", CassError::CASS_ERROR_LIB_UNABLE_TO_DETERMINE_PROTOCOL => { - "Unable to find supported protocol version\0" + c"Unable to find supported protocol version" } - CassError::CASS_ERROR_LIB_NULL_VALUE => "NULL value specified\0", - CassError::CASS_ERROR_LIB_NOT_IMPLEMENTED => "Not implemented\0", - CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT => "Unable to connect\0", - CassError::CASS_ERROR_LIB_UNABLE_TO_CLOSE => "Unable to close\0", - CassError::CASS_ERROR_LIB_NO_PAGING_STATE => "No paging state\0", - CassError::CASS_ERROR_LIB_PARAMETER_UNSET => "Parameter unset\0", - CassError::CASS_ERROR_LIB_INVALID_ERROR_RESULT_TYPE => "Invalid error result type\0", - CassError::CASS_ERROR_LIB_INVALID_FUTURE_TYPE => "Invalid future type\0", - CassError::CASS_ERROR_LIB_INTERNAL_ERROR => "Internal error\0", - CassError::CASS_ERROR_LIB_INVALID_CUSTOM_TYPE => "Invalid custom type\0", - CassError::CASS_ERROR_LIB_INVALID_DATA => "Invalid data\0", - CassError::CASS_ERROR_LIB_NOT_ENOUGH_DATA => "Not enough data\0", - CassError::CASS_ERROR_LIB_INVALID_STATE => "Invalid state\0", - CassError::CASS_ERROR_LIB_NO_CUSTOM_PAYLOAD => "No custom payload\0", + CassError::CASS_ERROR_LIB_NULL_VALUE => c"NULL value specified", + CassError::CASS_ERROR_LIB_NOT_IMPLEMENTED => c"Not implemented", + CassError::CASS_ERROR_LIB_UNABLE_TO_CONNECT => c"Unable to connect", + CassError::CASS_ERROR_LIB_UNABLE_TO_CLOSE => c"Unable to close", + CassError::CASS_ERROR_LIB_NO_PAGING_STATE => c"No paging state", + CassError::CASS_ERROR_LIB_PARAMETER_UNSET => c"Parameter unset", + CassError::CASS_ERROR_LIB_INVALID_ERROR_RESULT_TYPE => c"Invalid error result type", + CassError::CASS_ERROR_LIB_INVALID_FUTURE_TYPE => c"Invalid future type", + CassError::CASS_ERROR_LIB_INTERNAL_ERROR => c"Internal error", + CassError::CASS_ERROR_LIB_INVALID_CUSTOM_TYPE => c"Invalid custom type", + CassError::CASS_ERROR_LIB_INVALID_DATA => c"Invalid data", + CassError::CASS_ERROR_LIB_NOT_ENOUGH_DATA => c"Not enough data", + CassError::CASS_ERROR_LIB_INVALID_STATE => c"Invalid state", + CassError::CASS_ERROR_LIB_NO_CUSTOM_PAYLOAD => c"No custom payload", CassError::CASS_ERROR_LIB_EXECUTION_PROFILE_INVALID => { - "Invalid execution profile specified\0" + c"Invalid execution profile specified" } - CassError::CASS_ERROR_LIB_NO_TRACING_ID => "No tracing ID\0", - CassError::CASS_ERROR_SERVER_SERVER_ERROR => "Server error\0", - CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR => "Protocol error\0", - CassError::CASS_ERROR_SERVER_BAD_CREDENTIALS => "Bad credentials\0", - CassError::CASS_ERROR_SERVER_UNAVAILABLE => "Unavailable\0", - CassError::CASS_ERROR_SERVER_OVERLOADED => "Overloaded\0", - CassError::CASS_ERROR_SERVER_IS_BOOTSTRAPPING => "Is bootstrapping\0", - CassError::CASS_ERROR_SERVER_TRUNCATE_ERROR => "Truncate error\0", - CassError::CASS_ERROR_SERVER_WRITE_TIMEOUT => "Write timeout\0", - CassError::CASS_ERROR_SERVER_READ_TIMEOUT => "Read timeout\0", - CassError::CASS_ERROR_SERVER_READ_FAILURE => "Read failure\0", - CassError::CASS_ERROR_SERVER_FUNCTION_FAILURE => "Function failure\0", - CassError::CASS_ERROR_SERVER_WRITE_FAILURE => "Write failure\0", - CassError::CASS_ERROR_SERVER_SYNTAX_ERROR => "Syntax error\0", - CassError::CASS_ERROR_SERVER_UNAUTHORIZED => "Unauthorized\0", - CassError::CASS_ERROR_SERVER_INVALID_QUERY => "Invalid query\0", - CassError::CASS_ERROR_SERVER_CONFIG_ERROR => "Configuration error\0", - CassError::CASS_ERROR_SERVER_ALREADY_EXISTS => "Already exists\0", - CassError::CASS_ERROR_SERVER_UNPREPARED => "Unprepared\0", - CassError::CASS_ERROR_SSL_INVALID_CERT => "Unable to load certificate\0", - CassError::CASS_ERROR_SSL_INVALID_PRIVATE_KEY => "Unable to load private key\0", - CassError::CASS_ERROR_SSL_NO_PEER_CERT => "No peer certificate\0", - CassError::CASS_ERROR_SSL_INVALID_PEER_CERT => "Invalid peer certificate\0", + CassError::CASS_ERROR_LIB_NO_TRACING_ID => c"No tracing ID", + CassError::CASS_ERROR_SERVER_SERVER_ERROR => c"Server error", + CassError::CASS_ERROR_SERVER_PROTOCOL_ERROR => c"Protocol error", + CassError::CASS_ERROR_SERVER_BAD_CREDENTIALS => c"Bad credentials", + CassError::CASS_ERROR_SERVER_UNAVAILABLE => c"Unavailable", + CassError::CASS_ERROR_SERVER_OVERLOADED => c"Overloaded", + CassError::CASS_ERROR_SERVER_IS_BOOTSTRAPPING => c"Is bootstrapping", + CassError::CASS_ERROR_SERVER_TRUNCATE_ERROR => c"Truncate error", + CassError::CASS_ERROR_SERVER_WRITE_TIMEOUT => c"Write timeout", + CassError::CASS_ERROR_SERVER_READ_TIMEOUT => c"Read timeout", + CassError::CASS_ERROR_SERVER_READ_FAILURE => c"Read failure", + CassError::CASS_ERROR_SERVER_FUNCTION_FAILURE => c"Function failure", + CassError::CASS_ERROR_SERVER_WRITE_FAILURE => c"Write failure", + CassError::CASS_ERROR_SERVER_SYNTAX_ERROR => c"Syntax error", + CassError::CASS_ERROR_SERVER_UNAUTHORIZED => c"Unauthorized", + CassError::CASS_ERROR_SERVER_INVALID_QUERY => c"Invalid query", + CassError::CASS_ERROR_SERVER_CONFIG_ERROR => c"Configuration error", + CassError::CASS_ERROR_SERVER_ALREADY_EXISTS => c"Already exists", + CassError::CASS_ERROR_SERVER_UNPREPARED => c"Unprepared", + CassError::CASS_ERROR_SSL_INVALID_CERT => c"Unable to load certificate", + CassError::CASS_ERROR_SSL_INVALID_PRIVATE_KEY => c"Unable to load private key", + CassError::CASS_ERROR_SSL_NO_PEER_CERT => c"No peer certificate", + CassError::CASS_ERROR_SSL_INVALID_PEER_CERT => c"Invalid peer certificate", CassError::CASS_ERROR_SSL_IDENTITY_MISMATCH => { - "Certificate does not match host or IP address\0" + c"Certificate does not match host or IP address" } - CassError::CASS_ERROR_SSL_PROTOCOL_ERROR => "Protocol error\0", - CassError::CASS_ERROR_SSL_CLOSED => "Connection closed\0", - _ => "\0", + CassError::CASS_ERROR_SSL_PROTOCOL_ERROR => c"Protocol error", + CassError::CASS_ERROR_SSL_CLOSED => c"Connection closed", + _ => c"", }; - desc.as_ptr() as *const c_char + desc.as_ptr() } diff --git a/scylla-rust-wrapper/src/inet.rs b/scylla-rust-wrapper/src/inet.rs index 4222e9a5..19a651bb 100644 --- a/scylla-rust-wrapper/src/inet.rs +++ b/scylla-rust-wrapper/src/inet.rs @@ -1,7 +1,6 @@ use crate::argconv::*; use crate::cass_error::CassError; use crate::types::*; -use num_derive::FromPrimitive; use num_traits::FromPrimitive; use std::convert::TryFrom; use std::convert::TryInto; @@ -14,12 +13,33 @@ pub(crate) use crate::cass_inet_types::CassInet; #[repr(u8)] // address_length field in CassInet is cass_uint8_t #[allow(non_camel_case_types)] -#[derive(Debug, Copy, Clone, FromPrimitive)] +#[derive(Debug, Copy, Clone)] pub enum CassInetLength { CASS_INET_V4 = 4, CASS_INET_V6 = 16, } +// Need to implement manually, because of the clippy 0.1.83 lints: +// | `FromPrimitive` is not local +// | move the `impl` block outside of this constant `_IMPL_NUM_FromPrimitive_FOR_CassInetLength` +impl FromPrimitive for CassInetLength { + fn from_i64(n: i64) -> Option { + match n { + 4 => Some(Self::CASS_INET_V4), + 16 => Some(Self::CASS_INET_V6), + _ => None, + } + } + + fn from_u64(n: u64) -> Option { + match n { + 4 => Some(Self::CASS_INET_V4), + 16 => Some(Self::CASS_INET_V6), + _ => None, + } + } +} + unsafe fn cass_inet_init(address: *const cass_uint8_t, address_length: CassInetLength) -> CassInet { let mut array = [0; 16]; let length = address_length as usize; diff --git a/scylla-rust-wrapper/src/logging.rs b/scylla-rust-wrapper/src/logging.rs index 4a8603cb..07ebe4de 100644 --- a/scylla-rust-wrapper/src/logging.rs +++ b/scylla-rust-wrapper/src/logging.rs @@ -113,7 +113,7 @@ where severity: (*event.metadata().level()).into(), file: target.as_ptr() as *const c_char, line: event.metadata().line().unwrap_or(0) as i32, - function: "\0".as_ptr() as *const c_char, // ignored, as cannot be fetched from event metadata + function: c"".as_ptr() as *const c_char, // ignored, as cannot be fetched from event metadata message: str_to_arr(message), }; @@ -167,17 +167,17 @@ pub unsafe extern "C" fn cass_log_set_level(log_level: CassLogLevel) { #[no_mangle] pub unsafe extern "C" fn cass_log_level_string(log_level: CassLogLevel) -> *const c_char { let log_level_str = match log_level { - CassLogLevel::CASS_LOG_TRACE => "TRACE\0", - CassLogLevel::CASS_LOG_DEBUG => "DEBUG\0", - CassLogLevel::CASS_LOG_INFO => "INFO\0", - CassLogLevel::CASS_LOG_WARN => "WARN\0", - CassLogLevel::CASS_LOG_ERROR => "ERROR\0", - CassLogLevel::CASS_LOG_CRITICAL => "CRITICAL\0", - CassLogLevel::CASS_LOG_DISABLED => "DISABLED\0", - _ => "\0", + CassLogLevel::CASS_LOG_TRACE => c"TRACE", + CassLogLevel::CASS_LOG_DEBUG => c"DEBUG", + CassLogLevel::CASS_LOG_INFO => c"INFO", + CassLogLevel::CASS_LOG_WARN => c"WARN", + CassLogLevel::CASS_LOG_ERROR => c"ERROR", + CassLogLevel::CASS_LOG_CRITICAL => c"CRITICAL", + CassLogLevel::CASS_LOG_DISABLED => c"DISABLED", + _ => c"", }; - log_level_str.as_ptr() as *const c_char + log_level_str.as_ptr() } #[no_mangle] diff --git a/scylla-rust-wrapper/src/query_result.rs b/scylla-rust-wrapper/src/query_result.rs index 84761eb1..6f3383ec 100644 --- a/scylla-rust-wrapper/src/query_result.rs +++ b/scylla-rust-wrapper/src/query_result.rs @@ -1106,7 +1106,7 @@ pub unsafe extern "C" fn cass_row_get_column_by_name_n( is_case_sensitive = true; } - return row_from_raw + row_from_raw .result_metadata .col_specs .iter() @@ -1115,13 +1115,11 @@ pub unsafe extern "C" fn cass_row_get_column_by_name_n( is_case_sensitive && col_spec.name == name_str || !is_case_sensitive && col_spec.name.eq_ignore_ascii_case(name_str) }) - .map(|(index, _)| { - return match row_from_raw.columns.get(index) { - Some(value) => value as *const CassValue, - None => std::ptr::null(), - }; + .map(|(index, _)| match row_from_raw.columns.get(index) { + Some(value) => value as *const CassValue, + None => std::ptr::null(), }) - .unwrap_or(std::ptr::null()); + .unwrap_or(std::ptr::null()) } #[no_mangle]