Rocket.toml
[default.app] meili_url = "http://host:port/" meili_master_key = "key"
main.rs
#[derive(Serialize, Deserialize, Clone)]
#[serde(crate = "rocket::serde")]
struct AppConfig {
meili_url: String,
meili_master_key: String,
}
let fairing = AdHoc::on_ignite("load app config!", |rocket| async move {
let app_config = match rocket.figment().focus("app").extract::<AppConfig>() {
Ok(a) => a,
Err(e) => {
panic!("load app config error:{:?}", e);
}
};
let client = Client::new(app_config.meili_url, Some(app_config.meili_master_key));
rocket.manage(client)
});
rocket::build()
.attach(fairing)
标签:自定义,rocket,app,meili,master,key,config,rust From: https://www.cnblogs.com/zhouquan-1992-04-06/p/17468840.html