diff --git a/scylla-rust-wrapper/src/argconv.rs b/scylla-rust-wrapper/src/argconv.rs index 29dffbed..d7b1ed35 100644 --- a/scylla-rust-wrapper/src/argconv.rs +++ b/scylla-rust-wrapper/src/argconv.rs @@ -6,24 +6,24 @@ use std::os::raw::c_char; use std::ptr::NonNull; use std::sync::{Arc, Weak}; -pub unsafe fn ptr_to_cstr(ptr: *const c_char) -> Option<&'static str> { +pub(crate) unsafe fn ptr_to_cstr(ptr: *const c_char) -> Option<&'static str> { unsafe { CStr::from_ptr(ptr) }.to_str().ok() } -pub unsafe fn ptr_to_cstr_n(ptr: *const c_char, size: size_t) -> Option<&'static str> { +pub(crate) unsafe fn ptr_to_cstr_n(ptr: *const c_char, size: size_t) -> Option<&'static str> { if ptr.is_null() { return None; } std::str::from_utf8(unsafe { std::slice::from_raw_parts(ptr as *const u8, size as usize) }).ok() } -pub unsafe fn arr_to_cstr(arr: &[c_char]) -> Option<&'static str> { +pub(crate) unsafe fn arr_to_cstr(arr: &[c_char]) -> Option<&'static str> { let null_char = '\0' as c_char; let end_index = arr[..N].iter().position(|c| c == &null_char).unwrap_or(N); unsafe { ptr_to_cstr_n(arr.as_ptr(), end_index as size_t) } } -pub fn str_to_arr(s: &str) -> [c_char; N] { +pub(crate) fn str_to_arr(s: &str) -> [c_char; N] { let mut result = ['\0' as c_char; N]; // Max length must be null-terminated @@ -40,14 +40,14 @@ pub fn str_to_arr(s: &str) -> [c_char; N] { result } -pub unsafe fn write_str_to_c(s: &str, c_str: *mut *const c_char, c_strlen: *mut size_t) { +pub(crate) unsafe fn write_str_to_c(s: &str, c_str: *mut *const c_char, c_strlen: *mut size_t) { unsafe { *c_str = s.as_ptr() as *const c_char; *c_strlen = s.len() as u64; } } -pub unsafe fn strlen(ptr: *const c_char) -> size_t { +pub(crate) unsafe fn strlen(ptr: *const c_char) -> size_t { if ptr.is_null() { return 0; } @@ -55,7 +55,7 @@ pub unsafe fn strlen(ptr: *const c_char) -> size_t { } #[cfg(test)] -pub fn str_to_c_str_n(s: &str) -> (*const c_char, size_t) { +pub(crate) fn str_to_c_str_n(s: &str) -> (*const c_char, size_t) { let mut c_str = std::ptr::null(); let mut c_strlen = size_t::default(); @@ -198,7 +198,7 @@ impl Properties for (O, CM) { /// /// ## Memory layout /// We use repr(transparent), so the struct has the same layout as underlying [`Option>`]. -/// Thanks to https://doc.rust-lang.org/std/option/#representation optimization, +/// Thanks to , /// we are guaranteed, that for `T: Sized`, our struct has the same layout /// and function call ABI as simply [`NonNull`]. #[repr(transparent)] @@ -227,7 +227,7 @@ pub type CassBorrowedExclusivePtr<'a, T, CM> = CassPtr<'a, T, (Exclusive, CM)>; /// and then another method accepts `const T*`. #[cfg(test)] impl<'a, T: Sized, P: Properties> CassPtr<'a, T, P> { - pub fn into_c_const(self) -> CassPtr<'a, T, (P::Onwership, CConst)> { + pub(crate) fn into_c_const(self) -> CassPtr<'a, T, (P::Onwership, CConst)> { CassPtr { ptr: self.ptr, _phantom: PhantomData, @@ -306,7 +306,7 @@ impl CassPtr<'_, T, P> { /// Resulting pointer inherits the lifetime from the immutable borrow /// of original pointer. #[allow(clippy::needless_lifetimes)] - pub fn borrow<'a>(&'a self) -> CassPtr<'a, T, (Shared, P::CMutability)> { + pub(crate) fn borrow<'a>(&'a self) -> CassPtr<'a, T, (Shared, P::CMutability)> { CassPtr { ptr: self.ptr, _phantom: PhantomData, @@ -320,7 +320,8 @@ impl CassPtr<'_, T, (Exclusive, CMut)> { /// of original pointer. Since the method accepts a mutable reference /// to the original pointer, we enforce aliasing ^ mutability principle at compile time. #[allow(clippy::needless_lifetimes)] - pub fn borrow_mut<'a>(&'a mut self) -> CassPtr<'a, T, (Exclusive, CMut)> { + #[cfg_attr(not(test), expect(unused))] + pub(crate) fn borrow_mut<'a>(&'a mut self) -> CassPtr<'a, T, (Exclusive, CMut)> { CassPtr { ptr: self.ptr, _phantom: PhantomData, @@ -413,7 +414,7 @@ pub trait BoxFFI: Sized + origin_sealed::FromBoxSealed { /// The data should be allocated via [`Arc::new`], and then returned to the user as a pointer. /// The user is responsible for freeing the memory associated /// with the pointer using corresponding driver's API function. -pub trait ArcFFI: Sized + origin_sealed::FromArcSealed { +pub(crate) trait ArcFFI: Sized + origin_sealed::FromArcSealed { /// Creates a pointer from a valid reference to Arc-allocated data. /// Holder of the pointer borrows the pointee. #[allow(clippy::needless_lifetimes)] diff --git a/scylla-rust-wrapper/src/batch.rs b/scylla-rust-wrapper/src/batch.rs index 48628b54..770fcde3 100644 --- a/scylla-rust-wrapper/src/batch.rs +++ b/scylla-rust-wrapper/src/batch.rs @@ -16,8 +16,8 @@ use std::convert::TryInto; use std::sync::Arc; pub struct CassBatch { - pub state: Arc, - pub batch_request_timeout_ms: Option, + pub(crate) state: Arc, + pub(crate) batch_request_timeout_ms: Option, pub(crate) exec_profile: Option, } @@ -27,9 +27,9 @@ impl FFI for CassBatch { } #[derive(Clone)] -pub struct CassBatchState { - pub batch: Batch, - pub bound_values: Vec>>>, +pub(crate) struct CassBatchState { + pub(crate) batch: Batch, + pub(crate) bound_values: Vec>>>, } #[unsafe(no_mangle)] diff --git a/scylla-rust-wrapper/src/cass_error.rs b/scylla-rust-wrapper/src/cass_error.rs index ae9e1e88..96dec2ba 100644 --- a/scylla-rust-wrapper/src/cass_error.rs +++ b/scylla-rust-wrapper/src/cass_error.rs @@ -5,7 +5,7 @@ pub(crate) use crate::cass_error_types::{CassError, CassErrorSource}; use crate::execution_error::CassErrorResult; use crate::statement::UnknownNamedParameterError; -pub trait ToCassError { +pub(crate) trait ToCassError { fn to_cass_error(&self) -> CassError; } @@ -223,7 +223,7 @@ impl ToCassError for SerializationError { } } -pub trait CassErrorMessage { +pub(crate) trait CassErrorMessage { fn msg(&self) -> String; } diff --git a/scylla-rust-wrapper/src/cass_types.rs b/scylla-rust-wrapper/src/cass_types.rs index 089b1b42..ec8e9057 100644 --- a/scylla-rust-wrapper/src/cass_types.rs +++ b/scylla-rust-wrapper/src/cass_types.rs @@ -16,17 +16,17 @@ pub(crate) use crate::cass_data_types::CassValueType; #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq, Eq))] -pub struct UdtDataType { +pub(crate) struct UdtDataType { // Vec to preserve the order of types - pub field_types: Vec<(String, Arc)>, + pub(crate) field_types: Vec<(String, Arc)>, - pub keyspace: String, - pub name: String, - pub frozen: bool, + pub(crate) keyspace: String, + pub(crate) name: String, + pub(crate) frozen: bool, } impl UdtDataType { - pub fn new() -> UdtDataType { + pub(crate) fn new() -> UdtDataType { UdtDataType { field_types: Vec::new(), keyspace: "".to_string(), @@ -35,7 +35,7 @@ impl UdtDataType { } } - pub fn with_capacity(capacity: usize) -> UdtDataType { + pub(crate) fn with_capacity(capacity: usize) -> UdtDataType { UdtDataType { field_types: Vec::with_capacity(capacity), keyspace: "".to_string(), @@ -44,21 +44,13 @@ impl UdtDataType { } } - pub fn add_field(&mut self, name: String, field_type: Arc) { - self.field_types.push((name, field_type)); - } - - pub fn get_field_by_name(&self, name: &str) -> Option<&Arc> { + pub(crate) fn get_field_by_name(&self, name: &str) -> Option<&Arc> { self.field_types .iter() .find(|(field_name, _)| field_name == name) .map(|(_, t)| t) } - pub fn get_field_by_index(&self, index: usize) -> Option<&Arc> { - self.field_types.get(index).map(|(_, b)| b) - } - fn typecheck_equals(&self, other: &UdtDataType) -> bool { // See: https://github.com/scylladb/cpp-driver/blob/master/src/data_type.hpp#L354-L386 @@ -109,21 +101,21 @@ impl Default for UdtDataType { #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq, Eq))] -pub enum MapDataType { +pub(crate) enum MapDataType { Untyped, Key(Arc), KeyAndValue(Arc, Arc), } #[derive(Debug)] -pub struct CassColumnSpec { - pub name: String, - pub data_type: Arc, +pub(crate) struct CassColumnSpec { + pub(crate) name: String, + pub(crate) data_type: Arc, } #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq, Eq))] -pub enum CassDataTypeInner { +pub(crate) enum CassDataTypeInner { Value(CassValueType), Udt(UdtDataType), List { @@ -153,7 +145,7 @@ impl CassDataTypeInner { /// Checks for equality during typechecks. /// /// This takes into account the fact that tuples/collections may be untyped. - pub fn typecheck_equals(&self, other: &CassDataTypeInner) -> bool { + pub(crate) fn typecheck_equals(&self, other: &CassDataTypeInner) -> bool { match self { CassDataTypeInner::Value(t) => *t == other.get_value_type(), CassDataTypeInner::Udt(udt) => match other { @@ -248,20 +240,20 @@ impl Eq for CassDataType {} unsafe impl Sync for CassDataType {} impl CassDataType { - pub unsafe fn get_unchecked(&self) -> &CassDataTypeInner { + pub(crate) unsafe fn get_unchecked(&self) -> &CassDataTypeInner { unsafe { &*self.0.get() } } #[allow(clippy::mut_from_ref)] - pub unsafe fn get_mut_unchecked(&self) -> &mut CassDataTypeInner { + pub(crate) unsafe fn get_mut_unchecked(&self) -> &mut CassDataTypeInner { unsafe { &mut *self.0.get() } } - pub const fn new(inner: CassDataTypeInner) -> CassDataType { + pub(crate) const fn new(inner: CassDataTypeInner) -> CassDataType { CassDataType(UnsafeCell::new(inner)) } - pub fn new_arced(inner: CassDataTypeInner) -> Arc { + pub(crate) fn new_arced(inner: CassDataTypeInner) -> Arc { Arc::new(CassDataType(UnsafeCell::new(inner))) } } @@ -366,14 +358,14 @@ impl CassDataTypeInner { } } - pub fn get_udt_type(&self) -> &UdtDataType { + pub(crate) fn get_udt_type(&self) -> &UdtDataType { match self { CassDataTypeInner::Udt(udt) => udt, _ => panic!("Can get UDT out of non-UDT data type"), } } - pub fn get_value_type(&self) -> CassValueType { + pub(crate) fn get_value_type(&self) -> CassValueType { match &self { CassDataTypeInner::Value(value_data_type) => *value_data_type, CassDataTypeInner::Udt { .. } => CassValueType::CASS_VALUE_TYPE_UDT, @@ -386,7 +378,7 @@ impl CassDataTypeInner { } } -pub fn get_column_type(column_type: &ColumnType) -> CassDataType { +pub(crate) fn get_column_type(column_type: &ColumnType) -> CassDataType { use CollectionType::*; use ColumnType::*; let inner = match column_type { @@ -935,7 +927,7 @@ impl TryFrom for SerialConsistency { } } -pub fn make_batch_type(type_: CassBatchType) -> Option { +pub(crate) fn make_batch_type(type_: CassBatchType) -> Option { match type_ { CassBatchType::CASS_BATCH_TYPE_LOGGED => Some(BatchType::Logged), CassBatchType::CASS_BATCH_TYPE_UNLOGGED => Some(BatchType::Unlogged), diff --git a/scylla-rust-wrapper/src/cluster.rs b/scylla-rust-wrapper/src/cluster.rs index 7d7d825f..45a6b6fd 100644 --- a/scylla-rust-wrapper/src/cluster.rs +++ b/scylla-rust-wrapper/src/cluster.rs @@ -145,7 +145,7 @@ pub struct CassCustomPayload; // We want to make sure that the returned future does not depend // on the provided &CassCluster, hence the `static here. -pub fn build_session_builder( +pub(crate) fn build_session_builder( cluster: &CassCluster, ) -> impl Future + 'static { let known_nodes = cluster @@ -1194,6 +1194,7 @@ pub unsafe extern "C" fn cass_cluster_set_compression( let compression = match compression_type { CassCompressionType::CASS_COMPRESSION_LZ4 => Some(Compression::Lz4), CassCompressionType::CASS_COMPRESSION_SNAPPY => Some(Compression::Snappy), + CassCompressionType::CASS_COMPRESSION_NONE => None, _ => None, }; diff --git a/scylla-rust-wrapper/src/collection.rs b/scylla-rust-wrapper/src/collection.rs index de326a3b..540e199e 100644 --- a/scylla-rust-wrapper/src/collection.rs +++ b/scylla-rust-wrapper/src/collection.rs @@ -30,10 +30,9 @@ static UNTYPED_MAP_TYPE: LazyLock> = LazyLock::new(|| { #[derive(Clone)] pub struct CassCollection { - pub collection_type: CassCollectionType, - pub data_type: Option>, - pub capacity: usize, - pub items: Vec, + pub(crate) collection_type: CassCollectionType, + pub(crate) data_type: Option>, + pub(crate) items: Vec, } impl FFI for CassCollection { @@ -90,7 +89,7 @@ impl CassCollection { CassError::CASS_OK } - pub fn append_cql_value(&mut self, value: Option) -> CassError { + pub(crate) fn append_cql_value(&mut self, value: Option) -> CassError { let err = self.typecheck_on_append(&value); if err != CassError::CASS_OK { return err; @@ -150,7 +149,6 @@ pub unsafe extern "C" fn cass_collection_new( BoxFFI::into_ptr(Box::new(CassCollection { collection_type, data_type: None, - capacity, items: Vec::with_capacity(capacity), })) } @@ -182,7 +180,6 @@ unsafe extern "C" fn cass_collection_new_from_data_type( BoxFFI::into_ptr(Box::new(CassCollection { collection_type, data_type: Some(data_type), - capacity, items: Vec::with_capacity(capacity), })) } diff --git a/scylla-rust-wrapper/src/exec_profile.rs b/scylla-rust-wrapper/src/exec_profile.rs index 5d06f1d1..9c481242 100644 --- a/scylla-rust-wrapper/src/exec_profile.rs +++ b/scylla-rust-wrapper/src/exec_profile.rs @@ -69,10 +69,10 @@ impl CassExecProfile { /// Represents a non-empty execution profile name. #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] -pub struct ExecProfileName(String); +pub(crate) struct ExecProfileName(String); #[derive(Debug, PartialEq, Eq)] -pub struct EmptyProfileName; +pub(crate) struct EmptyProfileName; impl TryFrom for ExecProfileName { type Error = EmptyProfileName; diff --git a/scylla-rust-wrapper/src/future.rs b/scylla-rust-wrapper/src/future.rs index b20d2cd0..076679e1 100644 --- a/scylla-rust-wrapper/src/future.rs +++ b/scylla-rust-wrapper/src/future.rs @@ -33,8 +33,8 @@ pub type CassFutureCallback = Option< >; struct BoundCallback { - pub cb: CassFutureCallback, - pub data: *mut c_void, + cb: CassFutureCallback, + data: *mut c_void, } // *mut c_void is not Send, so Rust will have to take our word @@ -77,13 +77,13 @@ enum FutureError { struct JoinHandleTimeout(JoinHandle<()>); impl CassFuture { - pub fn make_raw( + pub(crate) fn make_raw( fut: impl Future + Send + 'static, ) -> CassOwnedSharedPtr { Self::new_from_future(fut).into_raw() } - pub fn new_from_future( + pub(crate) fn new_from_future( fut: impl Future + Send + 'static, ) -> Arc { let cass_fut = Arc::new(CassFuture { @@ -118,7 +118,9 @@ impl CassFuture { cass_fut } - pub fn new_ready(r: CassFutureResult) -> Arc { + // This is left just because it might be useful in tests. + #[expect(unused)] + pub(crate) fn new_ready(r: CassFutureResult) -> Arc { Arc::new(CassFuture { state: Mutex::new(CassFutureState::default()), result: OnceLock::from(r), @@ -126,7 +128,10 @@ impl CassFuture { }) } - pub fn with_waited_result<'s, T>(&'s self, f: impl FnOnce(&'s CassFutureResult) -> T) -> T + pub(crate) fn with_waited_result<'s, T>( + &'s self, + f: impl FnOnce(&'s CassFutureResult) -> T, + ) -> T where T: 's, { @@ -269,7 +274,7 @@ impl CassFuture { } } - pub unsafe fn set_callback( + pub(crate) unsafe fn set_callback( &self, self_ptr: CassBorrowedSharedPtr, cb: CassFutureCallback, diff --git a/scylla-rust-wrapper/src/integration_testing.rs b/scylla-rust-wrapper/src/integration_testing.rs index e49841a7..e8450f30 100644 --- a/scylla-rust-wrapper/src/integration_testing.rs +++ b/scylla-rust-wrapper/src/integration_testing.rs @@ -181,7 +181,7 @@ pub unsafe extern "C" fn testing_batch_set_sleeping_history_listener( /// /// Useful for testing purposes. #[derive(Debug)] -pub struct IgnoringRetryPolicy; +pub(crate) struct IgnoringRetryPolicy; #[derive(Debug)] struct IgnoringRetrySession; diff --git a/scylla-rust-wrapper/src/iterator.rs b/scylla-rust-wrapper/src/iterator.rs index 2c1f1032..a24869df 100644 --- a/scylla-rust-wrapper/src/iterator.rs +++ b/scylla-rust-wrapper/src/iterator.rs @@ -17,18 +17,18 @@ use crate::query_result::{ }; use crate::types::{cass_bool_t, cass_false, size_t}; -pub use crate::cass_iterator_types::CassIteratorType; +pub(crate) use crate::cass_iterator_types::CassIteratorType; use std::os::raw::c_char; use std::sync::Arc; -pub struct CassRowsResultIterator<'result> { +pub(crate) struct CassRowsResultIterator<'result> { iterator: TypedRowIterator<'result, 'result, CassRawRow<'result, 'result>>, result_metadata: &'result CassResultMetadata, current_row: Option>, } -pub enum CassResultIterator<'result> { +pub(crate) enum CassResultIterator<'result> { NonRows, Rows(CassRowsResultIterator<'result>), } @@ -65,7 +65,7 @@ impl CassResultIterator<'_> { } } -pub struct CassRowIterator<'result> { +pub(crate) struct CassRowIterator<'result> { row: &'result CassRow<'result>, position: Option, } @@ -81,7 +81,7 @@ impl CassRowIterator<'_> { } /// An iterator created from [`cass_iterator_from_collection()`] with list or set provided as a value. -pub struct CassListlikeIterator<'result> { +pub(crate) struct CassListlikeIterator<'result> { iterator: ListlikeIterator<'result, 'result, CassRawValue<'result, 'result>>, value_data_type: &'result Arc, current_value: Option>, @@ -133,7 +133,7 @@ impl<'result> CassListlikeIterator<'result> { /// Iterator created from [`cass_iterator_from_collection()`] with map provided as a collection. /// Single iteration (call to [`cass_iterator_next()`]) moves the iterator to the next value (either key or value). -pub struct CassMapCollectionIterator<'result> { +pub(crate) struct CassMapCollectionIterator<'result> { iterator: CassMapIterator<'result>, state: Option, } @@ -180,7 +180,7 @@ impl<'result> CassMapCollectionIterator<'result> { } /// Iterator created from [`cass_iterator_from_collection()`] with list, set or map provided as a collection. -pub enum CassCollectionIterator<'result> { +pub(crate) enum CassCollectionIterator<'result> { /// Listlike iterator for list or set. Listlike(CassListlikeIterator<'result>), /// Map iterator. @@ -330,13 +330,13 @@ mod tuple_iterator { } /// Iterator created from [`cass_iterator_from_tuple()`]. -pub struct CassTupleIterator<'result> { +pub(crate) struct CassTupleIterator<'result> { iterator: tuple_iterator::TupleIterator<'result, 'result>, metadata: &'result [Arc], current_entry: Option>, } -pub struct CassTupleIteratorEntry<'result> { +pub(crate) struct CassTupleIteratorEntry<'result> { field_value: CassValue<'result>, metadata_types_index: usize, } @@ -405,7 +405,7 @@ impl<'result> CassTupleIterator<'result> { /// Iterator created from [`cass_iterator_from_map()`]. /// Single iteration (call to [`cass_iterator_next()`]) moves the iterator to the next entry (key-value pair). -pub struct CassMapIterator<'result> { +pub(crate) struct CassMapIterator<'result> { iterator: MapIterator< 'result, 'result, @@ -470,7 +470,7 @@ impl<'result> CassMapIterator<'result> { } } -pub struct CassUdtIterator<'result> { +pub(crate) struct CassUdtIterator<'result> { iterator: UdtIterator<'result, 'result>, metadata: &'result [(String, Arc)], current_entry: Option>, @@ -549,7 +549,7 @@ impl<'result> CassUdtIterator<'result> { } } -pub struct CassSchemaMetaIterator<'schema> { +pub(crate) struct CassSchemaMetaIterator<'schema> { value: &'schema CassSchemaMeta, count: usize, position: Option, @@ -565,7 +565,7 @@ impl CassSchemaMetaIterator<'_> { } } -pub struct CassKeyspaceMetaIterator<'schema> { +pub(crate) struct CassKeyspaceMetaIterator<'schema> { value: &'schema CassKeyspaceMeta, count: usize, position: Option, @@ -581,7 +581,7 @@ impl CassKeyspaceMetaIterator<'_> { } } -pub struct CassTableMetaIterator<'schema> { +pub(crate) struct CassTableMetaIterator<'schema> { value: &'schema CassTableMeta, count: usize, position: Option, @@ -597,7 +597,7 @@ impl CassTableMetaIterator<'_> { } } -pub struct CassViewMetaIterator<'schema> { +pub(crate) struct CassViewMetaIterator<'schema> { value: &'schema CassMaterializedViewMeta, count: usize, position: Option, @@ -617,7 +617,7 @@ impl CassViewMetaIterator<'_> { /// Can be constructed from either table ([`cass_iterator_columns_from_table_meta()`]) /// or view metadata ([`cass_iterator_columns_from_materialized_view_meta()`]). /// To be used by [`cass_iterator_get_column_meta()`]. -pub enum CassColumnsMetaIterator<'schema> { +pub(crate) enum CassColumnsMetaIterator<'schema> { FromTable(CassTableMetaIterator<'schema>), FromView(CassViewMetaIterator<'schema>), } @@ -626,7 +626,7 @@ pub enum CassColumnsMetaIterator<'schema> { /// Can be constructed from either keyspace ([`cass_iterator_materialized_views_from_keyspace_meta()`]) /// or table ([`cass_iterator_materialized_views_from_table_meta()`]) metadata. /// To be used by [`cass_iterator_get_materialized_view_meta()`]. -pub enum CassMaterializedViewsMetaIterator<'schema> { +pub(crate) enum CassMaterializedViewsMetaIterator<'schema> { FromKeyspace(CassKeyspaceMetaIterator<'schema>), FromTable(CassTableMetaIterator<'schema>), } diff --git a/scylla-rust-wrapper/src/lib.rs b/scylla-rust-wrapper/src/lib.rs index 1ec2b0b8..ebe6f1a3 100644 --- a/scylla-rust-wrapper/src/lib.rs +++ b/scylla-rust-wrapper/src/lib.rs @@ -10,39 +10,39 @@ use tokio::runtime::Runtime; mod binding; // pub, because doctests defined in `argconv` module need to access it. pub mod argconv; -pub mod batch; -pub mod cass_error; -pub mod cass_types; -pub mod cluster; -pub mod collection; -pub mod date_time; -pub mod exec_profile; -pub mod execution_error; +pub(crate) mod batch; +pub(crate) mod cass_error; +pub(crate) mod cass_types; +pub(crate) mod cluster; +pub(crate) mod collection; +pub(crate) mod date_time; +pub(crate) mod exec_profile; +pub(crate) mod execution_error; mod external; -pub mod future; -pub mod inet; +pub(crate) mod future; +pub(crate) mod inet; #[cfg(cpp_integration_testing)] -pub mod integration_testing; -pub mod iterator; +pub(crate) mod integration_testing; +pub(crate) mod iterator; mod load_balancing; mod logging; -pub mod metadata; -pub mod misc; -pub mod prepared; -pub mod query_result; -pub mod retry_policy; +pub(crate) mod metadata; +pub(crate) mod misc; +pub(crate) mod prepared; +pub(crate) mod query_result; +pub(crate) mod retry_policy; #[cfg(test)] mod ser_de_tests; -pub mod session; -pub mod ssl; -pub mod statement; +pub(crate) mod session; +pub(crate) mod ssl; +pub(crate) mod statement; #[cfg(test)] -pub mod testing; -pub mod timestamp_generator; -pub mod tuple; -pub mod user_type; -pub mod uuid; -pub mod value; +pub(crate) mod testing; +pub(crate) mod timestamp_generator; +pub(crate) mod tuple; +pub(crate) mod user_type; +pub(crate) mod uuid; +pub(crate) mod value; /// Includes a file generated by bindgen called `filename`. macro_rules! include_bindgen_generated { @@ -52,85 +52,100 @@ macro_rules! include_bindgen_generated { } /// All numeric types are defined here. -pub mod types { +pub(crate) mod types { #![allow(non_camel_case_types)] // for `cass_false` and `cass_true` globals. #![allow(non_upper_case_globals)] + #![allow(unused)] // Definition for size_t (and possibly other types in the future) include_bindgen_generated!("basic_types.rs"); } /// CassError, CassErrorSource, CassWriteType -pub mod cass_error_types { +pub(crate) mod cass_error_types { + #![allow(unused)] include_bindgen_generated!("cppdriver_error_types.rs"); } /// CassValueType -pub mod cass_data_types { +pub(crate) mod cass_data_types { + #![allow(unused)] include_bindgen_generated!("cppdriver_data_types.rs"); } /// CassConsistency -pub mod cass_consistency_types { +pub(crate) mod cass_consistency_types { + #![allow(unused)] include_bindgen_generated!("cppdriver_consistency_types.rs"); } /// CassBatchType -pub mod cass_batch_types { +pub(crate) mod cass_batch_types { + #![allow(unused)] include_bindgen_generated!("cppdriver_batch_types.rs"); } /// CassCompressionType -pub mod cass_compression_types { +pub(crate) mod cass_compression_types { + #![allow(unused)] include_bindgen_generated!("cppdriver_compression_types.rs"); } /// CassCollectionType -pub mod cass_collection_types { +pub(crate) mod cass_collection_types { + #![allow(unused)] include_bindgen_generated!("cppdriver_collection_types.rs"); } /// CassInet -pub mod cass_inet_types { +pub(crate) mod cass_inet_types { + #![allow(unused)] #![allow(non_camel_case_types, non_snake_case)] include_bindgen_generated!("cppdriver_inet_types.rs"); } /// CassLogLevel, CassLogMessage -pub mod cass_log_types { +pub(crate) mod cass_log_types { + #![allow(unused)] #![allow(non_camel_case_types, non_snake_case)] include_bindgen_generated!("cppdriver_log_types.rs"); } /// CassColumnType -pub mod cass_column_types { +pub(crate) mod cass_column_types { + #![allow(unused)] + include_bindgen_generated!("cppdriver_column_type.rs"); } /// CassUuid -pub mod cass_uuid_types { +pub(crate) mod cass_uuid_types { + #![allow(unused)] #![allow(non_camel_case_types, non_snake_case)] include_bindgen_generated!("cppdriver_uuid_types.rs"); } /// CassIteratorType -pub mod cass_iterator_types { +pub(crate) mod cass_iterator_types { + #![allow(unused)] + include_bindgen_generated!("cppdriver_iterator_types.rs"); } /// CassMetrics -pub mod cass_metrics_types { +pub(crate) mod cass_metrics_types { + #![allow(unused)] #![allow(non_camel_case_types, non_snake_case)] include_bindgen_generated!("cppdriver_metrics_types.rs"); } -pub static RUNTIME: LazyLock = LazyLock::new(|| Runtime::new().unwrap()); -pub static LOGGER: LazyLock> = LazyLock::new(|| { +pub(crate) static RUNTIME: LazyLock = LazyLock::new(|| Runtime::new().unwrap()); +pub(crate) static LOGGER: LazyLock> = LazyLock::new(|| { RwLock::new(Logger { cb: Some(stderr_log_callback), data: std::ptr::null_mut(), diff --git a/scylla-rust-wrapper/src/logging.rs b/scylla-rust-wrapper/src/logging.rs index bf0960fc..13ee9cf7 100644 --- a/scylla-rust-wrapper/src/logging.rs +++ b/scylla-rust-wrapper/src/logging.rs @@ -30,9 +30,9 @@ unsafe extern "C" fn noop_log_callback( ) { } -pub struct Logger { - pub cb: CassLogCallback, - pub data: *mut c_void, +pub(crate) struct Logger { + pub(crate) cb: CassLogCallback, + pub(crate) data: *mut c_void, } // The field `data` in the struct `Logger` is neither Send nor Sync. @@ -71,7 +71,7 @@ impl TryFrom for Level { } } -pub const CASS_LOG_MAX_MESSAGE_SIZE: usize = 1024; +pub(crate) const CASS_LOG_MAX_MESSAGE_SIZE: usize = 1024; pub unsafe extern "C" fn stderr_log_callback( message: CassBorrowedSharedPtr, @@ -89,9 +89,9 @@ pub unsafe extern "C" fn stderr_log_callback( ) } -pub struct CustomLayer; +pub(crate) struct CustomLayer; -pub struct PrintlnVisitor { +pub(crate) struct PrintlnVisitor { log_message: String, } @@ -152,7 +152,7 @@ where // Sets tracing subscriber with specified `level`. // The subscriber is valid for the duration of the entire program. -pub fn set_tracing_subscriber_with_level(level: Level) { +pub(crate) fn set_tracing_subscriber_with_level(level: Level) { tracing::subscriber::set_global_default( tracing_subscriber::registry() .with( diff --git a/scylla-rust-wrapper/src/metadata.rs b/scylla-rust-wrapper/src/metadata.rs index 576ec85c..ca68a71e 100644 --- a/scylla-rust-wrapper/src/metadata.rs +++ b/scylla-rust-wrapper/src/metadata.rs @@ -10,7 +10,7 @@ use std::sync::Arc; use std::sync::Weak; pub struct CassSchemaMeta { - pub keyspaces: HashMap, + pub(crate) keyspaces: HashMap, } impl FFI for CassSchemaMeta { @@ -18,12 +18,12 @@ impl FFI for CassSchemaMeta { } pub struct CassKeyspaceMeta { - pub name: String, + pub(crate) name: String, // User defined type name to type - pub user_defined_type_data_type: HashMap>, - pub tables: HashMap>, - pub views: HashMap>, + pub(crate) user_defined_type_data_type: HashMap>, + pub(crate) tables: HashMap>, + pub(crate) views: HashMap>, } // Owned by CassSchemaMeta @@ -32,13 +32,13 @@ impl FFI for CassKeyspaceMeta { } pub struct CassTableMeta { - pub name: String, - pub columns_metadata: HashMap, - pub partition_keys: Vec, - pub clustering_keys: Vec, + pub(crate) name: String, + pub(crate) columns_metadata: HashMap, + pub(crate) partition_keys: Vec, + pub(crate) clustering_keys: Vec, /// Non-key columns sorted alphabetically by name. - pub non_key_sorted_columns: Vec, - pub views: HashMap>, + pub(crate) non_key_sorted_columns: Vec, + pub(crate) views: HashMap>, } // Either: @@ -49,9 +49,9 @@ impl FFI for CassTableMeta { } pub struct CassMaterializedViewMeta { - pub name: String, - pub view_metadata: CassTableMeta, - pub base_table: Weak, + pub(crate) name: String, + pub(crate) view_metadata: CassTableMeta, + pub(crate) base_table: Weak, } // Shared ownership by CassKeyspaceMeta and CassTableMeta @@ -60,9 +60,9 @@ impl FFI for CassMaterializedViewMeta { } pub struct CassColumnMeta { - pub name: String, - pub column_type: Arc, - pub column_kind: CassColumnType, + pub(crate) name: String, + pub(crate) column_type: Arc, + pub(crate) column_kind: CassColumnType, } // Owned by CassTableMeta @@ -70,7 +70,7 @@ impl FFI for CassColumnMeta { type Origin = FromRef; } -pub fn create_table_metadata(table_name: &str, table_metadata: &Table) -> CassTableMeta { +pub(crate) fn create_table_metadata(table_name: &str, table_metadata: &Table) -> CassTableMeta { let mut columns_metadata = HashMap::new(); table_metadata .columns @@ -670,6 +670,7 @@ pub unsafe extern "C" fn cass_materialized_view_meta_partition_key_count( view_meta.view_metadata.partition_keys.len() as size_t } +#[unsafe(no_mangle)] pub unsafe extern "C" fn cass_materialized_view_meta_partition_key( view_meta: CassBorrowedSharedPtr, index: size_t, @@ -704,6 +705,7 @@ pub unsafe extern "C" fn cass_materialized_view_meta_clustering_key_count( view_meta.view_metadata.clustering_keys.len() as size_t } +#[unsafe(no_mangle)] pub unsafe extern "C" fn cass_materialized_view_meta_clustering_key( view_meta: CassBorrowedSharedPtr, index: size_t, diff --git a/scylla-rust-wrapper/src/prepared.rs b/scylla-rust-wrapper/src/prepared.rs index 23a57d91..95f6eaf1 100644 --- a/scylla-rust-wrapper/src/prepared.rs +++ b/scylla-rust-wrapper/src/prepared.rs @@ -15,16 +15,16 @@ use scylla::statement::prepared::PreparedStatement; #[derive(Debug, Clone)] pub struct CassPrepared { // Data types of columns from PreparedMetadata. - pub variable_col_data_types: Vec>, + pub(crate) variable_col_data_types: Vec>, // Cached result metadata. Arc'ed since we want to share it // with result metadata after execution. - pub result_metadata: Arc, - pub statement: PreparedStatement, + pub(crate) result_metadata: Arc, + pub(crate) statement: PreparedStatement, } impl CassPrepared { - pub fn new_from_prepared_statement(mut statement: PreparedStatement) -> Self { + pub(crate) fn new_from_prepared_statement(mut statement: PreparedStatement) -> Self { // We already cache the metadata on cpp-rust-driver side (see CassPrepared::result_metadata field), // thus we can enable the optimization on rust-driver side as well. This will prevent the server // from sending redundant bytes representing a result metadata during EXECUTE. @@ -52,7 +52,7 @@ impl CassPrepared { } } - pub fn get_variable_data_type_by_name(&self, name: &str) -> Option<&Arc> { + pub(crate) fn get_variable_data_type_by_name(&self, name: &str) -> Option<&Arc> { let index = self .statement .get_variable_col_specs() diff --git a/scylla-rust-wrapper/src/query_result.rs b/scylla-rust-wrapper/src/query_result.rs index 36816530..df629839 100644 --- a/scylla-rust-wrapper/src/query_result.rs +++ b/scylla-rust-wrapper/src/query_result.rs @@ -30,13 +30,13 @@ use thiserror::Error; use uuid::Uuid; #[derive(Debug)] -pub enum CassResultKind { +pub(crate) enum CassResultKind { NonRows, Rows(CassRowsResult), } #[derive(Debug)] -pub struct CassRowsResult { +pub(crate) struct CassRowsResult { // Arc: shared with first_row (yoke). pub(crate) shared_data: Arc, pub(crate) first_row: Option, @@ -58,9 +58,9 @@ impl FFI for CassNode { #[derive(Debug)] pub struct CassResult { - pub tracing_id: Option, - pub paging_state_response: PagingStateResponse, - pub kind: CassResultKind, + pub(crate) tracing_id: Option, + pub(crate) paging_state_response: PagingStateResponse, + pub(crate) kind: CassResultKind, // None only for tests - currently no way to mock coordinator in rust-driver. // Should be able to do so under "cpp_rust_unstable". pub(crate) coordinator: Option, @@ -71,7 +71,7 @@ impl CassResult { /// - query result /// - paging state response /// - optional cached result metadata - it's provided for prepared statements - pub fn from_result_payload( + pub(crate) fn from_result_payload( result: QueryResult, paging_state_response: PagingStateResponse, maybe_result_metadata: Option>, @@ -127,12 +127,12 @@ impl FFI for CassResult { } #[derive(Debug)] -pub struct CassResultMetadata { - pub col_specs: Vec, +pub(crate) struct CassResultMetadata { + pub(crate) col_specs: Vec, } impl CassResultMetadata { - pub fn from_column_specs(col_specs: ColumnSpecs<'_, '_>) -> CassResultMetadata { + pub(crate) fn from_column_specs(col_specs: ColumnSpecs<'_, '_>) -> CassResultMetadata { let col_specs = col_specs .iter() .map(|col_spec| { @@ -165,8 +165,8 @@ impl<'frame, 'metadata> DeserializeRow<'frame, 'metadata> for CassRawRow<'frame, /// It will be freed, when CassResult is freed.(see #[cass_result_free]) #[derive(Debug)] pub struct CassRow<'result> { - pub columns: Vec>, - pub result_metadata: &'result CassResultMetadata, + pub(crate) columns: Vec>, + pub(crate) result_metadata: &'result CassResultMetadata, } impl FFI for CassRow<'_> { @@ -249,7 +249,7 @@ mod row_with_self_borrowed_result_data { /// This struct is a shared owner of the row bytes and metadata, and self-borrows this data /// to the `CassRow` it contains. #[derive(Debug)] - pub struct RowWithSelfBorrowedResultData( + pub(crate) struct RowWithSelfBorrowedResultData( Yoke, Arc>, ); @@ -446,7 +446,7 @@ impl FFI for CassValue<'_> { } impl<'result> CassValue<'result> { - pub fn get_non_null(&'result self) -> Result + pub(crate) fn get_non_null(&'result self) -> Result where T: DeserializeValue<'result, 'result>, { @@ -460,7 +460,7 @@ impl<'result> CassValue<'result> { Ok(v) } - pub fn get_bytes_non_null(&self) -> Result<&'result [u8], NonNullDeserializationError> { + pub(crate) fn get_bytes_non_null(&self) -> Result<&'result [u8], NonNullDeserializationError> { let Some(slice) = self.value.slice() else { return Err(NonNullDeserializationError::IsNull); }; @@ -470,7 +470,7 @@ impl<'result> CassValue<'result> { } #[derive(Debug, Error)] -pub enum NonNullDeserializationError { +pub(crate) enum NonNullDeserializationError { #[error("Value is null")] IsNull, #[error("Typecheck failed: {0}")] diff --git a/scylla-rust-wrapper/src/retry_policy.rs b/scylla-rust-wrapper/src/retry_policy.rs index 40a34b98..1e437ce7 100644 --- a/scylla-rust-wrapper/src/retry_policy.rs +++ b/scylla-rust-wrapper/src/retry_policy.rs @@ -7,7 +7,7 @@ use std::sync::Arc; use crate::argconv::{ArcFFI, CMut, CassBorrowedSharedPtr, CassOwnedSharedPtr, FFI, FromArc}; #[derive(Debug)] -pub struct CassLoggingRetryPolicy { +pub(crate) struct CassLoggingRetryPolicy { child_policy: Arc, } diff --git a/scylla-rust-wrapper/src/session.rs b/scylla-rust-wrapper/src/session.rs index 44bf0e13..a48f2dd5 100644 --- a/scylla-rust-wrapper/src/session.rs +++ b/scylla-rust-wrapper/src/session.rs @@ -33,7 +33,7 @@ use std::sync::Arc; use std::time::Duration; use tokio::sync::RwLock; -pub struct CassSessionInner { +pub(crate) struct CassSessionInner { session: Session, exec_profile_map: HashMap, client_id: uuid::Uuid, diff --git a/scylla-rust-wrapper/src/ssl.rs b/scylla-rust-wrapper/src/ssl.rs index b138d08e..71f039c6 100644 --- a/scylla-rust-wrapper/src/ssl.rs +++ b/scylla-rust-wrapper/src/ssl.rs @@ -23,10 +23,10 @@ impl FFI for CassSsl { type Origin = FromArc; } -pub const CASS_SSL_VERIFY_NONE: i32 = 0x00; -pub const CASS_SSL_VERIFY_PEER_CERT: i32 = 0x01; -pub const CASS_SSL_VERIFY_PEER_IDENTITY: i32 = 0x02; -pub const CASS_SSL_VERIFY_PEER_IDENTITY_DNS: i32 = 0x04; +pub(crate) const CASS_SSL_VERIFY_NONE: i32 = 0x00; +pub(crate) const CASS_SSL_VERIFY_PEER_CERT: i32 = 0x01; +pub(crate) const CASS_SSL_VERIFY_PEER_IDENTITY: i32 = 0x02; +pub(crate) const CASS_SSL_VERIFY_PEER_IDENTITY_DNS: i32 = 0x04; #[unsafe(no_mangle)] pub unsafe extern "C" fn cass_ssl_new() -> CassOwnedSharedPtr { diff --git a/scylla-rust-wrapper/src/statement.rs b/scylla-rust-wrapper/src/statement.rs index e9f87976..648cd241 100644 --- a/scylla-rust-wrapper/src/statement.rs +++ b/scylla-rust-wrapper/src/statement.rs @@ -36,10 +36,10 @@ pub enum BoundStatement { } #[derive(Clone)] -pub struct BoundPreparedStatement { +pub(crate) struct BoundPreparedStatement { // Arc is needed, because PreparedStatement is passed by reference to session.execute - pub statement: Arc, - pub bound_values: Vec>>, + pub(crate) statement: Arc, + pub(crate) bound_values: Vec>>, } impl BoundPreparedStatement { @@ -111,10 +111,10 @@ impl BoundPreparedStatement { } #[derive(Clone)] -pub struct BoundSimpleQuery { - pub query: Statement, - pub bound_values: Vec>>, - pub name_to_bound_index: HashMap, +pub(crate) struct BoundSimpleQuery { + pub(crate) query: Statement, + pub(crate) bound_values: Vec>>, + pub(crate) name_to_bound_index: HashMap, } impl BoundSimpleQuery { @@ -166,14 +166,14 @@ impl BoundSimpleQuery { /// but we also store the name-to-index mapping in `name_to_bound_index` map. /// Having this information, and prepared metadata provided in serialization context, /// we can build a resulting vector of bound values. -pub struct SimpleQueryRowSerializer { - pub bound_values: Vec>>, - pub name_to_bound_index: HashMap, +pub(crate) struct SimpleQueryRowSerializer { + pub(crate) bound_values: Vec>>, + pub(crate) name_to_bound_index: HashMap, } #[derive(Debug, Error)] #[error("Unknown named parameter \"{0}\"")] -pub struct UnknownNamedParameterError(String); +pub(crate) struct UnknownNamedParameterError(String); impl SerializeRow for SimpleQueryRowSerializer { fn serialize( @@ -212,10 +212,10 @@ impl SerializeRow for SimpleQueryRowSerializer { } pub struct CassStatement { - pub statement: BoundStatement, - pub paging_state: PagingState, - pub paging_enabled: bool, - pub request_timeout_ms: Option, + pub(crate) statement: BoundStatement, + pub(crate) paging_state: PagingState, + pub(crate) paging_enabled: bool, + pub(crate) request_timeout_ms: Option, pub(crate) exec_profile: Option, } diff --git a/scylla-rust-wrapper/src/tuple.rs b/scylla-rust-wrapper/src/tuple.rs index 81f831c5..e5ae8478 100644 --- a/scylla-rust-wrapper/src/tuple.rs +++ b/scylla-rust-wrapper/src/tuple.rs @@ -13,8 +13,8 @@ static UNTYPED_TUPLE_TYPE: LazyLock> = #[derive(Clone)] pub struct CassTuple { - pub data_type: Option>, - pub items: Vec>, + pub(crate) data_type: Option>, + pub(crate) items: Vec>, } impl FFI for CassTuple { diff --git a/scylla-rust-wrapper/src/user_type.rs b/scylla-rust-wrapper/src/user_type.rs index 53b07a57..946ab101 100644 --- a/scylla-rust-wrapper/src/user_type.rs +++ b/scylla-rust-wrapper/src/user_type.rs @@ -8,10 +8,10 @@ use std::sync::Arc; #[derive(Clone)] pub struct CassUserType { - pub data_type: Arc, + pub(crate) data_type: Arc, // Vec to preserve the order of fields - pub field_values: Vec>, + pub(crate) field_values: Vec>, } impl FFI for CassUserType { diff --git a/scylla-rust-wrapper/src/uuid.rs b/scylla-rust-wrapper/src/uuid.rs index e5d686bc..f9036249 100644 --- a/scylla-rust-wrapper/src/uuid.rs +++ b/scylla-rust-wrapper/src/uuid.rs @@ -13,8 +13,8 @@ use uuid::Uuid; pub(crate) use crate::cass_uuid_types::CassUuid; pub struct CassUuidGen { - pub clock_seq_and_node: cass_uint64_t, - pub last_timestamp: AtomicU64, + pub(crate) clock_seq_and_node: cass_uint64_t, + pub(crate) last_timestamp: AtomicU64, } impl FFI for CassUuidGen { diff --git a/scylla-rust-wrapper/src/value.rs b/scylla-rust-wrapper/src/value.rs index 6f59db63..06933778 100644 --- a/scylla-rust-wrapper/src/value.rs +++ b/scylla-rust-wrapper/src/value.rs @@ -27,7 +27,7 @@ use crate::cass_types::{CassDataType, CassValueType}; /// we need to serialize the counter value using `CassCqlValue::BigInt`. #[derive(Clone, Debug)] #[cfg_attr(test, derive(PartialEq))] -pub enum CassCqlValue { +pub(crate) enum CassCqlValue { TinyInt(i8), SmallInt(i16), Int(i32), @@ -68,7 +68,7 @@ pub enum CassCqlValue { // TODO: custom (?), duration and decimal } -pub fn is_type_compatible(value: &Option, typ: &CassDataType) -> bool { +pub(crate) fn is_type_compatible(value: &Option, typ: &CassDataType) -> bool { match value { Some(v) => v.is_type_compatible(typ), None => true, @@ -76,7 +76,7 @@ pub fn is_type_compatible(value: &Option, typ: &CassDataType) -> b } impl CassCqlValue { - pub fn is_type_compatible(&self, typ: &CassDataType) -> bool { + pub(crate) fn is_type_compatible(&self, typ: &CassDataType) -> bool { match self { CassCqlValue::TinyInt(_) => unsafe { typ.get_unchecked().get_value_type() == CassValueType::CASS_VALUE_TYPE_TINY_INT @@ -267,12 +267,12 @@ impl CassCqlValue { /// Serialization of one of the built-in types failed. #[derive(Debug, Clone)] -pub struct CassSerializationError { +pub(crate) struct CassSerializationError { /// Name of the Rust type being serialized. - pub rust_name: &'static str, + pub(crate) rust_name: &'static str, /// Detailed information about the failure. - pub kind: BuiltinSerializationErrorKind, + pub(crate) kind: BuiltinSerializationErrorKind, } impl std::fmt::Display for CassSerializationError {