Repository: AlexPikalov/cdrs (language: rust)

Issue:
Adapt examples to ssl feature
Reported in #61 

>When --all-features was used, the ssl transport
was provided via the transport_ssl module.
However, the examples were not prepared for this,
and cargo test --all-features would fail.
>
>As both transports are mutually exclusive, it
seems reasonable to just use the same module name
and make life easier for clients.

- [x] fix existing examples
- [x] add examples which would use ssl


Discussion / hints:

Fix patch:
diff --git a/examples/batch_queries.rs b/examples/batch_queries.rs
index 4e3eb40..2c431e6 100644
--- a/examples/batch_queries.rs
+++ b/examples/batch_queries.rs
@@ -1,23 +1,29 @@
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports)]
 extern crate cdrs;
 
 use cdrs::client::CDRS;
 use cdrs::query::BatchQueryBuilder;
 use cdrs::authenticators::PasswordAuthenticator;
 use cdrs::compression::Compression;
+#[cfg(not(feature = "ssl"))]
 use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
 // default credentials
-const USER: &'static str = "cassandra";
-const PASS: &'static str = "cassandra";
-const ADDR: &'static str = "127.0.0.1:9042";
+const _USER: &'static str = "cassandra";
+const _PASS: &'static str = "cassandra";
+const _ADDR: &'static str = "127.0.0.1:9042";
 
 /// First create a keyspace 'keyspace'.
 /// Then create a new table of integers:
 /// CREATE TABLE keyspace.integers (integer int PRIMARY KEY);
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
-    let authenticator = PasswordAuthenticator::new(USER, PASS);
-    let tcp_transport = Transport::new(ADDR).unwrap();
+    let authenticator = PasswordAuthenticator::new(_USER, _PASS);
+    let tcp_transport = Transport::new(_ADDR).unwrap();
     let client = CDRS::new(tcp_transport, authenticator);
     let mut session = client.start(Compression::None).unwrap();
 
@@ -43,3 +49,8 @@ fn main() {
 
     println!("batch result {:?}", batched.get_body());
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!()
+}
diff --git a/examples/connection_pool.rs b/examples/connection_pool.rs
index 34fd761..d932a5f 100644
--- a/examples/connection_pool.rs
+++ b/examples/connection_pool.rs
@@ -1,3 +1,5 @@
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports, unused_variables)]
 extern crate cdrs;
 extern crate r2d2;
 
@@ -5,22 +7,26 @@ use std::thread;
 use std::sync::mpsc::channel;
 
 use cdrs::connection_manager::ConnectionManager;
-use cdrs::transport::Transport;
 use cdrs::authenticators::PasswordAuthenticator;
 use cdrs::compression::Compression;
 use cdrs::query::QueryBuilder;
+#[cfg(not(feature = "ssl"))]
+use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
 // default credentials
-const USER: &'static str = "cassandra";
-const PASS: &'static str = "cassandra";
-const ADDR: &'static str = "127.0.0.1:9042";
+const _USER: &'static str = "cassandra";
+const _PASS: &'static str = "cassandra";
+const _ADDR: &'static str = "127.0.0.1:9042";
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
     let config = r2d2::Config::builder()
         .pool_size(15)
         .build();
-    let transport = Transport::new(ADDR).unwrap();
-    let authenticator = PasswordAuthenticator::new(USER, PASS);
+    let transport = Transport::new(_ADDR).unwrap();
+    let authenticator = PasswordAuthenticator::new(_USER, _PASS);
     let manager = ConnectionManager::new(transport, authenticator, Compression::None);
 
     let pool = r2d2::Pool::new(config, manager).unwrap();
@@ -48,3 +54,8 @@ fn main() {
         println!("{:?}", res);
     }
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!()
+}
diff --git a/examples/create_table.rs b/examples/create_table.rs
index d08c3b3..a95d932 100644
--- a/examples/create_table.rs
+++ b/examples/create_table.rs
@@ -1,3 +1,5 @@
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports, unused_variables)]
 extern crate cdrs;
 
 use cdrs::client::CDRS;
@@ -5,16 +7,20 @@ use cdrs::query::QueryBuilder;
 use cdrs::authenticators::PasswordAuthenticator;
 use cdrs::compression::Compression;
 use cdrs::consistency::Consistency;
+#[cfg(not(feature = "ssl"))]
 use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
 // default credentials
-const USER: &'static str = "cassandra";
-const PASS: &'static str = "cassandra";
-const ADDR: &'static str = "127.0.0.1:9042";
+const _USER: &'static str = "cassandra";
+const _PASS: &'static str = "cassandra";
+const _ADDR: &'static str = "127.0.0.1:9042";
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
-    let authenticator = PasswordAuthenticator::new(USER, PASS);
-    let tcp_transport = Transport::new(ADDR).unwrap();
+    let authenticator = PasswordAuthenticator::new(_USER, _PASS);
+    let tcp_transport = Transport::new(_ADDR).unwrap();
     let client = CDRS::new(tcp_transport, authenticator);
     let mut session = client.start(Compression::None).unwrap();
 
@@ -38,3 +44,8 @@ fn main() {
         Err(ref err) => println!("Error occured: {:?}", err)
     }
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!()
+}
diff --git a/examples/prepare_execute.rs b/examples/prepare_execute.rs
index 917cb10..d9696f2 100644
--- a/examples/prepare_execute.rs
+++ b/examples/prepare_execute.rs
@@ -1,3 +1,5 @@
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports, unused_variables)]
 extern crate cdrs;
 
 use cdrs::client::CDRS;
@@ -5,16 +7,20 @@ use cdrs::query::QueryParamsBuilder;
 use cdrs::authenticators::PasswordAuthenticator;
 use cdrs::compression::Compression;
 use cdrs::consistency::Consistency;
+#[cfg(not(feature = "ssl"))]
 use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
 // default credentials
-const USER: &'static str = "cassandra";
-const PASS: &'static str = "cassandra";
-const ADDR: &'static str = "127.0.0.1:9042";
+const _USER: &'static str = "cassandra";
+const _PASS: &'static str = "cassandra";
+const _ADDR: &'static str = "127.0.0.1:9042";
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
-    let authenticator = PasswordAuthenticator::new(USER, PASS);
-    let tcp_transport = Transport::new(ADDR).unwrap();
+    let authenticator = PasswordAuthenticator::new(_USER, _PASS);
+    let tcp_transport = Transport::new(_ADDR).unwrap();
     let client = CDRS::new(tcp_transport, authenticator);
     let mut session = client.start(Compression::None).unwrap();
 
@@ -41,3 +47,8 @@ fn main() {
 
     println!("executed:\n{:?}", executed);
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!()
+}
diff --git a/examples/read_table_into_struct.rs b/examples/read_table_into_struct.rs
index c941c21..1234890 100644
--- a/examples/read_table_into_struct.rs
+++ b/examples/read_table_into_struct.rs
@@ -1,11 +1,15 @@
-
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports, unused_variables)]
 extern crate cdrs;
 use cdrs::client::CDRS;
 use cdrs::query::QueryBuilder;
 use cdrs::authenticators::PasswordAuthenticator;
 use cdrs::compression::Compression;
 use cdrs::types::IntoRustByName;
+#[cfg(not(feature = "ssl"))]
 use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
 /// this example is to pull employee records from emp table
 ///
@@ -39,6 +43,7 @@ struct Employee {
     pub emp_phone: i64,
 }
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
 
     let authenticator = PasswordAuthenticator::new("user", "pass");
@@ -97,3 +102,8 @@ fn main() {
     }
 
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!()
+}
diff --git a/examples/server_events.rs b/examples/server_events.rs
index dd40083..9e0ed58 100644
--- a/examples/server_events.rs
+++ b/examples/server_events.rs
@@ -1,22 +1,28 @@
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports, unused_variables)]
 extern crate cdrs;
 extern crate r2d2;
 
 use std::thread;
 
 use cdrs::client::CDRS;
-use cdrs::transport::Transport;
 use cdrs::authenticators::PasswordAuthenticator;
 use cdrs::compression::Compression;
 use cdrs::frame::events::SimpleServerEvent;
+#[cfg(not(feature = "ssl"))]
+use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
 // default credentials
-const USER: &'static str = "cassandra";
-const PASS: &'static str = "cassandra";
-const ADDR: &'static str = "127.0.0.1:9042";
+const _USER: &'static str = "cassandra";
+const _PASS: &'static str = "cassandra";
+const _ADDR: &'static str = "127.0.0.1:9042";
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
-    let transport = Transport::new(ADDR).unwrap();
-    let authenticator = PasswordAuthenticator::new(USER, PASS);
+    let transport = Transport::new(_ADDR).unwrap();
+    let authenticator = PasswordAuthenticator::new(_USER, _PASS);
     let client = CDRS::new(transport, authenticator);
     let session = client.start(Compression::None).unwrap();
 
@@ -32,3 +38,8 @@ fn main() {
         println!("server event {:?}", event.get_body());
     }
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!()
+}
diff --git a/examples/simple.rs b/examples/simple.rs
index 92b3e48..56198f2 100644
--- a/examples/simple.rs
+++ b/examples/simple.rs
@@ -1,10 +1,15 @@
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports, unused_variables)]
 extern crate cdrs;
-use cdrs::client::{CDRS};
+use cdrs::client::CDRS;
 use cdrs::query::QueryBuilder;
 use cdrs::authenticators::NoneAuthenticator;
 use cdrs::compression::Compression;
 use cdrs::types::IntoRustByName;
+#[cfg(not(feature = "ssl"))]
 use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
 /// this example is to pull employee records from emp table
 ///
@@ -38,6 +43,7 @@ struct Employee {
     pub emp_phone: i64,
 }
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
 
     let addr = "127.0.0.1:9042";
@@ -95,3 +101,8 @@ fn main() {
     }
 
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!()
+}
diff --git a/examples/simple_with_auth.rs b/examples/simple_with_auth.rs
index 0fb61c6..87a7d45 100644
--- a/examples/simple_with_auth.rs
+++ b/examples/simple_with_auth.rs
@@ -1,11 +1,16 @@
-
+// in feature="ssl" imports are unused until examples are implemented
+#![allow(unused_imports, unused_variables)]
 extern crate cdrs;
 use cdrs::client::CDRS;
 use cdrs::query::QueryBuilder;
 use cdrs::authenticators::PasswordAuthenticator;
 use cdrs::compression::Compression;
+#[cfg(not(feature = "ssl"))]
 use cdrs::transport::Transport;
+#[cfg(feature = "ssl")]
+use cdrs::transport_ssl::Transport;
 
+#[cfg(not(feature = "ssl"))]
 fn main() {
 
     let authenticator = PasswordAuthenticator::new("user", "pass");
@@ -40,3 +45,8 @@ fn main() {
 
 
 }
+
+#[cfg(feature = "ssl")]
+fn main() {
+    unimplemented!();
+}


Test patch: