The accepted answer works, but if you wanted to avoid needing a special formatted environment variable for rocket, you can also update the figment prior to starting rocket.
For example:
#[launch]async fn rocket() -> _ { let figment = rocket::Config::figment().merge(("databases.my_db.url", env::var("DATABASE_URL").expect("DATABASE_URL must be set"), )); rocket::custom(figment) // equivalent to rocket::build()}