macro_rules! client_config {
($opts:ident) => { ... };
($opts:ident; $db_url:tt) => { ... };
}
Expand description
Creates a new configuration structure to initialize the MongoDB client
Create a new configuration structure to initialize the MongoDB client with a standard environment variable
use mongodb_macro::Parser;
mongodb_macro::client_config!(Opts);
fn main() {
std::env::set_var("MONGODB_HOST", "localhost");
std::env::set_var("DB_URL", "mongodb://root:root@${MONGODB_HOST}:27017");
let opts = Opts::parse();
assert_eq!(&opts.db_url, "mongodb://root:root@localhost:27017");
}
Create a new configuration structure to initialize the MongoDB client with the specified environment variable
use mongodb_macro::Parser;
mongodb_macro::client_config!(Opts; "MONGO_DB_URL");
fn main() {
std::env::set_var("MONGODB_HOST", "localhost");
std::env::set_var("MONGO_DB_URL", "mongodb://root:root@${MONGODB_HOST}:27017");
let opts = Opts::parse();
assert_eq!(&opts.db_url, "mongodb://root:root@localhost:27017");
}