Quantcast
Channel: Active questions tagged rest - Stack Overflow
Viewing all articles
Browse latest Browse all 4056

How to return global object from a Rocket REST API? [duplicate]

$
0
0

I'm starting to learn Rust and the Rocket framework. How do I return my_universe that I created on the first line of main() when calling GET /universe/ports/21?

fn main() {    let my_universe = universe::model::Universe::new();    rocket::ignite().mount("/universe", routes![ports]).launch();}#[get("/ports/<id>")]fn ports(id: u16) -> universe::model::Universe {    // need to return my_universe here}

The issue I'm having is that if I define my_universe within ports(), it'll recreate the the object on each request. Instead, I need the route to return the same my_universe object on each request.


Viewing all articles
Browse latest Browse all 4056

Trending Articles