I want to be able to do something with my state once the server starts shutting down
example:
struct MyConfig {
user_val: String
}
#[get("/hello")]
fn hello(config: &State<MyConfig>) -> Result<String, error::Error> {
//do stuff
Ok(&config.user_val)
}
#[rocket::main]
async fn main() -> Result<(), error::Error> {
let config = MyConfig{user_val: "hello".to_string()};
let _rocket = rocket::build()
.manage(config) //cant pass as borrow because it wont live long enough
.mount("/", routes![hello])
.launch()
.await?;
println!("{}", &config.user_val); //cant access because value moved
Ok(())
}
The result should be when I shut down the program it prints user_val(I dont want to clone)
but after setting it as a state its no longer accessible after the server ends