Skip to content

Commit

Permalink
Merge pull request #958 from Lorak-mmk/remove-unreachable-pubs
Browse files Browse the repository at this point in the history
Remove unreachable pubs
  • Loading branch information
wprzytula authored Mar 14, 2024
2 parents 7b3e73e + ce0e9f7 commit 245ae7d
Show file tree
Hide file tree
Showing 19 changed files with 116 additions and 102 deletions.
3 changes: 3 additions & 0 deletions scylla-cql/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ num-bigint-03 = ["dep:num-bigint-03"]
num-bigint-04 = ["dep:num-bigint-04"]
bigdecimal-04 = ["dep:bigdecimal-04"]
full-serialization = ["chrono", "time", "secret", "num-bigint-03", "num-bigint-04", "bigdecimal-04"]

[lints.rust]
unreachable_pub = "warn"
5 changes: 4 additions & 1 deletion scylla-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,7 @@ proc-macro = true
darling = "0.20.0"
syn = "2.0"
quote = "1.0"
proc-macro2 = "1.0"
proc-macro2 = "1.0"

[lints.rust]
unreachable_pub = "warn"
2 changes: 1 addition & 1 deletion scylla-macros/src/from_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use quote::{quote, quote_spanned};
use syn::{spanned::Spanned, DeriveInput};

/// #[derive(FromRow)] derives FromRow for struct
pub fn from_row_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
pub(crate) fn from_row_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
let item = syn::parse::<DeriveInput>(tokens_input)?;
let path = crate::parser::get_path(&item)?;
let struct_fields = crate::parser::parse_named_fields(&item, "FromRow")?;
Expand Down
2 changes: 1 addition & 1 deletion scylla-macros/src/from_user_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use quote::{quote, quote_spanned};
use syn::{spanned::Spanned, DeriveInput};

/// #[derive(FromUserType)] allows to parse a struct as User Defined Type
pub fn from_user_type_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
pub(crate) fn from_user_type_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
let item = syn::parse::<DeriveInput>(tokens_input)?;
let path = crate::parser::get_path(&item)?;
let struct_fields = crate::parser::parse_named_fields(&item, "FromUserType")?;
Expand Down
2 changes: 1 addition & 1 deletion scylla-macros/src/into_user_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use quote::{quote, quote_spanned};
use syn::{spanned::Spanned, DeriveInput};

/// #[derive(IntoUserType)] allows to parse a struct as User Defined Type
pub fn into_user_type_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
pub(crate) fn into_user_type_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
let item = syn::parse::<DeriveInput>(tokens_input)?;
let path = crate::parser::get_path(&item)?;
let struct_fields = crate::parser::parse_named_fields(&item, "IntoUserType")?;
Expand Down
2 changes: 1 addition & 1 deletion scylla-macros/src/serialize/cql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ struct Context {
fields: Vec<Field>,
}

pub fn derive_serialize_cql(tokens_input: TokenStream) -> Result<syn::ItemImpl, syn::Error> {
pub(crate) fn derive_serialize_cql(tokens_input: TokenStream) -> Result<syn::ItemImpl, syn::Error> {
let input: syn::DeriveInput = syn::parse(tokens_input)?;
let struct_name = input.ident.clone();
let named_fields = crate::parser::parse_named_fields(&input, "SerializeCql")?;
Expand Down
2 changes: 1 addition & 1 deletion scylla-macros/src/serialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ struct Context {
fields: Vec<Field>,
}

pub fn derive_serialize_row(tokens_input: TokenStream) -> Result<syn::ItemImpl, syn::Error> {
pub(crate) fn derive_serialize_row(tokens_input: TokenStream) -> Result<syn::ItemImpl, syn::Error> {
let input: syn::DeriveInput = syn::parse(tokens_input)?;
let struct_name = input.ident.clone();
let named_fields = crate::parser::parse_named_fields(&input, "SerializeRow")?;
Expand Down
2 changes: 1 addition & 1 deletion scylla-macros/src/value_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use syn::DeriveInput;

/// #[derive(ValueList)] allows to parse a struct as a list of values,
/// which can be fed to the query directly.
pub fn value_list_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
pub(crate) fn value_list_derive(tokens_input: TokenStream) -> Result<TokenStream, syn::Error> {
let item = syn::parse::<DeriveInput>(tokens_input)?;
let path = crate::parser::get_path(&item)?;
let struct_fields = crate::parser::parse_named_fields(&item, "ValueList")?;
Expand Down
2 changes: 2 additions & 0 deletions scylla-proxy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,5 @@ ntest = "0.9.0"
tracing-subscriber = { version = "0.3.14", features = ["env-filter"] }
tokio = { version = "1.12", features = ["signal"] }

[lints.rust]
unreachable_pub = "warn"
86 changes: 44 additions & 42 deletions scylla-proxy/src/actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ use crate::{
frame::{FrameOpcode, FrameParams, RequestFrame, RequestOpcode, ResponseFrame, ResponseOpcode},
TargetShard,
};
use scylla_cql::{
errors::{DbError, WriteType},
Consistency,
};
use scylla_cql::errors::DbError;

/// Specifies when an associated [Reaction] will be performed.
/// Conditions are subject to logic, with `not()`, `and()` and `or()`
Expand Down Expand Up @@ -407,8 +404,13 @@ impl RequestReaction {
}
}

struct ExampleDbErrors;
impl ExampleDbErrors {
pub mod example_db_errors {
use bytes::Bytes;
use scylla_cql::{
errors::{DbError, WriteType},
Consistency,
};

pub fn syntax_error() -> DbError {
DbError::SyntaxError
}
Expand Down Expand Up @@ -507,84 +509,84 @@ pub struct ResponseForger;

impl ResponseForger {
pub fn syntax_error(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::syntax_error())
RequestReaction::forge_with_error(example_db_errors::syntax_error())
}
pub fn invalid(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::invalid())
RequestReaction::forge_with_error(example_db_errors::invalid())
}
pub fn already_exists(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::already_exists())
RequestReaction::forge_with_error(example_db_errors::already_exists())
}
pub fn function_failure(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::function_failure())
RequestReaction::forge_with_error(example_db_errors::function_failure())
}
pub fn authentication_error(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::authentication_error())
RequestReaction::forge_with_error(example_db_errors::authentication_error())
}
pub fn unauthorized(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::unauthorized())
RequestReaction::forge_with_error(example_db_errors::unauthorized())
}
pub fn config_error(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::config_error())
RequestReaction::forge_with_error(example_db_errors::config_error())
}
pub fn unavailable(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::unavailable())
RequestReaction::forge_with_error(example_db_errors::unavailable())
}
pub fn overloaded(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::overloaded())
RequestReaction::forge_with_error(example_db_errors::overloaded())
}
pub fn is_bootstrapping(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::is_bootstrapping())
RequestReaction::forge_with_error(example_db_errors::is_bootstrapping())
}
pub fn truncate_error(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::truncate_error())
RequestReaction::forge_with_error(example_db_errors::truncate_error())
}
pub fn read_timeout(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::read_timeout())
RequestReaction::forge_with_error(example_db_errors::read_timeout())
}
pub fn write_timeout(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::write_timeout())
RequestReaction::forge_with_error(example_db_errors::write_timeout())
}
pub fn read_failure(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::read_failure())
RequestReaction::forge_with_error(example_db_errors::read_failure())
}
pub fn write_failure(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::write_failure())
RequestReaction::forge_with_error(example_db_errors::write_failure())
}
pub fn unprepared(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::unprepared())
RequestReaction::forge_with_error(example_db_errors::unprepared())
}
pub fn server_error(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::server_error())
RequestReaction::forge_with_error(example_db_errors::server_error())
}
pub fn protocol_error(&self) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::protocol_error())
RequestReaction::forge_with_error(example_db_errors::protocol_error())
}
pub fn other(&self, num: i32) -> RequestReaction {
RequestReaction::forge_with_error(ExampleDbErrors::other(num))
RequestReaction::forge_with_error(example_db_errors::other(num))
}
pub fn random_error(&self) -> RequestReaction {
self.random_error_with_delay(None)
}
pub fn random_error_with_delay(&self, delay: Option<Duration>) -> RequestReaction {
static ERRORS: &[fn() -> DbError] = &[
ExampleDbErrors::invalid,
ExampleDbErrors::already_exists,
ExampleDbErrors::function_failure,
ExampleDbErrors::authentication_error,
ExampleDbErrors::unauthorized,
ExampleDbErrors::config_error,
ExampleDbErrors::unavailable,
ExampleDbErrors::overloaded,
ExampleDbErrors::is_bootstrapping,
ExampleDbErrors::truncate_error,
ExampleDbErrors::read_timeout,
ExampleDbErrors::write_timeout,
ExampleDbErrors::write_failure,
ExampleDbErrors::unprepared,
ExampleDbErrors::server_error,
ExampleDbErrors::protocol_error,
|| ExampleDbErrors::other(2137),
example_db_errors::invalid,
example_db_errors::already_exists,
example_db_errors::function_failure,
example_db_errors::authentication_error,
example_db_errors::unauthorized,
example_db_errors::config_error,
example_db_errors::unavailable,
example_db_errors::overloaded,
example_db_errors::is_bootstrapping,
example_db_errors::truncate_error,
example_db_errors::read_timeout,
example_db_errors::write_timeout,
example_db_errors::write_failure,
example_db_errors::unprepared,
example_db_errors::server_error,
example_db_errors::protocol_error,
|| example_db_errors::other(2137),
];
RequestReaction::forge_with_error_lazy_delay(
Box::new(|| ERRORS[rand::thread_rng().next_u32() as usize % ERRORS.len()]()),
Expand Down
2 changes: 1 addition & 1 deletion scylla-proxy/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub(crate) enum FrameType {
}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum FrameOpcode {
pub(crate) enum FrameOpcode {
Request(RequestOpcode),
Response(ResponseOpcode),
}
Expand Down
3 changes: 2 additions & 1 deletion scylla-proxy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ mod proxy;
pub type TargetShard = u16;

pub use actions::{
Action, Condition, Reaction, RequestReaction, RequestRule, ResponseReaction, ResponseRule,
example_db_errors, Action, Condition, Reaction, RequestReaction, RequestRule, ResponseReaction,
ResponseRule,
};
pub use errors::{DoorkeeperError, ProxyError, WorkerError};
pub use frame::{RequestFrame, RequestOpcode, ResponseFrame, ResponseOpcode};
Expand Down
3 changes: 3 additions & 0 deletions scylla/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,3 +70,6 @@ time = "0.3"
[[bench]]
name = "benchmark"
harness = false

[lints.rust]
unreachable_pub = "warn"
34 changes: 17 additions & 17 deletions scylla/src/transport/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,15 +301,15 @@ mod ssl_config {
// for the particular node. (The SslConfig must be different, because SNIs differ for different nodes.)
// Thenceforth, all connections to that node share the same SslConfig.
#[derive(Clone)]
pub struct SslConfig {
pub(crate) struct SslConfig {
context: SslContext,
#[cfg(feature = "cloud")]
sni: Option<String>,
}

impl SslConfig {
// Used in case when the user provided their own SslContext to be used in all connections.
pub fn new_with_global_context(context: SslContext) -> Self {
pub(crate) fn new_with_global_context(context: SslContext) -> Self {
Self {
context,
#[cfg(feature = "cloud")]
Expand Down Expand Up @@ -349,24 +349,24 @@ mod ssl_config {
}

#[derive(Clone)]
pub struct ConnectionConfig {
pub compression: Option<Compression>,
pub tcp_nodelay: bool,
pub tcp_keepalive_interval: Option<Duration>,
pub(crate) struct ConnectionConfig {
pub(crate) compression: Option<Compression>,
pub(crate) tcp_nodelay: bool,
pub(crate) tcp_keepalive_interval: Option<Duration>,
#[cfg(feature = "ssl")]
pub ssl_config: Option<SslConfig>,
pub connect_timeout: std::time::Duration,
pub(crate) ssl_config: Option<SslConfig>,
pub(crate) connect_timeout: std::time::Duration,
// should be Some only in control connections,
pub event_sender: Option<mpsc::Sender<Event>>,
pub default_consistency: Consistency,
pub(crate) event_sender: Option<mpsc::Sender<Event>>,
pub(crate) default_consistency: Consistency,
#[cfg(feature = "cloud")]
pub(crate) cloud_config: Option<Arc<CloudConfig>>,
pub authenticator: Option<Arc<dyn AuthenticatorProvider>>,
pub address_translator: Option<Arc<dyn AddressTranslator>>,
pub enable_write_coalescing: bool,
pub(crate) authenticator: Option<Arc<dyn AuthenticatorProvider>>,
pub(crate) address_translator: Option<Arc<dyn AddressTranslator>>,
pub(crate) enable_write_coalescing: bool,

pub keepalive_interval: Option<Duration>,
pub keepalive_timeout: Option<Duration>,
pub(crate) keepalive_interval: Option<Duration>,
pub(crate) keepalive_timeout: Option<Duration>,
}

impl Default for ConnectionConfig {
Expand Down Expand Up @@ -395,7 +395,7 @@ impl Default for ConnectionConfig {

impl ConnectionConfig {
#[cfg(feature = "ssl")]
pub fn is_ssl(&self) -> bool {
fn is_ssl(&self) -> bool {
#[cfg(feature = "cloud")]
if self.cloud_config.is_some() {
return true;
Expand All @@ -404,7 +404,7 @@ impl ConnectionConfig {
}

#[cfg(not(feature = "ssl"))]
pub fn is_ssl(&self) -> bool {
fn is_ssl(&self) -> bool {
false
}
}
Expand Down
Loading

0 comments on commit 245ae7d

Please sign in to comment.