diff --git a/src/config.rs b/src/config.rs index 3daf29c..a1501bc 100644 --- a/src/config.rs +++ b/src/config.rs @@ -182,8 +182,8 @@ pub struct ConnectionConf { pub ssl_key_file: Option, /// Datacenter name - #[clap(long("datacenter"), required = false, default_value = "")] - pub datacenter: String, + #[clap(long("datacenter"), required = false)] + pub datacenter: Option, /// Default CQL query consistency level #[clap(long("consistency"), required = false, default_value = "LOCAL_QUORUM")] diff --git a/src/context.rs b/src/context.rs index e96eb20..23a560e 100644 --- a/src/context.rs +++ b/src/context.rs @@ -62,8 +62,7 @@ fn ssl_context(conf: &&ConnectionConf) -> Result, CassError> /// Configures connection to Cassandra. pub async fn connect(conf: &ConnectionConf) -> Result { let mut policy_builder = DefaultPolicy::builder().token_aware(true); - let dc = &conf.datacenter; - if !dc.is_empty() { + if let Some(dc) = &conf.datacenter { policy_builder = policy_builder .prefer_datacenter(dc.to_owned()) .permit_dc_failover(true); diff --git a/src/report.rs b/src/report.rs index ba8165d..cfed4f9 100644 --- a/src/report.rs +++ b/src/report.rs @@ -512,7 +512,9 @@ impl<'a> Display for RunConfigCmp<'a> { } let lines: Vec> = vec![ - self.line("Datacenter", "", |conf| conf.connection.datacenter.clone()), + self.line("Datacenter", "", |conf| { + conf.connection.datacenter.clone().unwrap_or_default() + }), self.line("Consistency", "", |conf| { conf.connection.consistency.scylla_consistency().to_string() }),