How to store this variable globally instead of passing it all over?



I am trying to use this library:

In order to do this properly, I need to initialize the connection as such:
// connect to redis
let client = try!(redis::Client::open(“redis://”));
let con = try!(client.get_connection());

Ideally I could have con as a global variable but I can’t start it it as a null, since rust doesn’t support nulls, and I believe I can’t call a function before main executes to set those variables.

Should I just initialize con in main and pad it all over? Is there a better way to do this? Ideally I’d like a standalone library and my calling functions don’t have to deal with this.

Thank you!!


If you really want it to be global, one option is


You can use an Option and initialize it with None.


What about a thread local?