cdrs
cdrs copied to clipboard
How can I resolve anonymous/staticpassword dynamically?
I was trying to make my credentials configurable. Like this:
let session = if let Some((user, pass)) = pass {
let auth = StaticPasswordAuthenticator::new(user, pass);
let node = NodeTcpConfigBuilder::new("127.0.0.1:9042", auth).build();
let cluster_config = ClusterTcpConfig(vec![node]);
session::new(&cluster_config, RoundRobin::new()).expect("session should be created")
} else {
let auth = NoneAuthenticator {};
let node = NodeTcpConfigBuilder::new("127.0.0.1:9042", auth).build();
let cluster_config = ClusterTcpConfig(vec![node]);
session::new(&cluster_config, RoundRobin::new()).expect("session should be created")
};
That obviously fails as it will generate incompatible types. What would be the proper way?