Use '#[rocket::launch]' in guide examples.

This commit is contained in:
Jeb Rosen 2020-07-11 09:42:05 -07:00
parent 2c82b3e1d5
commit 2b3d8110f1
8 changed files with 39 additions and 57 deletions

View File

@ -54,10 +54,9 @@ And finally, create a skeleton Rocket application to work off of in
#[macro_use] extern crate rocket;
fn main() {
# if false {
rocket::ignite().launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite()
}
```
@ -113,10 +112,9 @@ to them. To mount the `index` route, modify the main function so that it reads:
# #[macro_use] extern crate rocket;
# #[get("/")] fn index() { }
fn main() {
# if false {
rocket::ignite().mount("/", routes![index]).launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![index])
}
```
@ -294,10 +292,9 @@ Ensure that the route is mounted at the root path:
# #[get("/")] fn index() {}
# #[post("/")] fn upload() {}
fn main() {
# if false {
rocket::ignite().mount("/", routes![index, upload]).launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![index, upload])
}
```
@ -358,10 +355,9 @@ Make sure that the route is mounted at the root path:
# #[post("/")] fn upload() {}
# #[get("/<id>")] fn retrieve(id: String) {}
fn main() {
# if false {
rocket::ignite().mount("/", routes![index, upload, retrieve]).launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![index, upload, retrieve])
}
```

View File

@ -66,10 +66,9 @@ fn index() -> &'static str {
"Hello, world!"
}
fn main() {
# if false {
rocket::ignite().mount("/", routes![index]).launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![index])
}
```

View File

@ -159,8 +159,8 @@ requests via the `launch` method. The method starts up the server and waits for
incoming requests. When a request arrives, Rocket finds the matching route and
dispatches the request to the route's handler.
We typically call `launch` from the `main` function. Our complete _Hello,
world!_ application thus looks like:
We typically use `#[rocket::launch]`, which generates a `main` function.
Our complete _Hello, world!_ application thus looks like:
```rust
#![feature(proc_macro_hygiene)]
@ -172,10 +172,9 @@ fn world() -> &'static str {
"Hello, world!"
}
fn main() {
# if false {
rocket::ignite().mount("/hello", routes![world]).launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/hello", routes![world])
}
```

View File

@ -222,12 +222,9 @@ fn user_int(id: isize) { /* ... */ }
#[get("/user/<id>", rank = 3)]
fn user_str(id: &RawStr) { /* ... */ }
fn main() {
# if false {
rocket::ignite()
.mount("/", routes![user, user_int, user_str])
.launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![user, user_int, user_str])
}
```

View File

@ -303,12 +303,9 @@ use rocket_contrib::databases::diesel;
#[database("sqlite_logs")]
struct LogsDbConn(diesel::SqliteConnection);
fn main() {
# if false {
rocket::ignite()
.attach(LogsDbConn::fairing())
.launch();
# }
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().attach(LogsDbConn::fairing())
}
```

View File

@ -49,15 +49,15 @@ example, the following snippet attached two fairings, `req_fairing` and
`res_fairing`, to a new Rocket instance:
```rust
# let req_fairing = rocket::fairing::AdHoc::on_request("example", |_, _| Box::pin(async {}));
# let res_fairing = rocket::fairing::AdHoc::on_response("example", |_, _| Box::pin(async {}));
#[rocket::launch]
fn rocket() -> rocket::Rocket {
# let req_fairing = rocket::fairing::AdHoc::on_request("example", |_, _| Box::pin(async {}));
# let res_fairing = rocket::fairing::AdHoc::on_response("example", |_, _| Box::pin(async {}));
# if false {
rocket::ignite()
.attach(req_fairing)
.attach(res_fairing)
.launch();
# }
rocket::ignite()
.attach(req_fairing)
.attach(res_fairing)
}
```
[`attach`]: @api/rocket/struct.Rocket.html#method.attach

View File

@ -125,15 +125,10 @@ fn hello() -> &'static str {
"Hello, world!"
}
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite().mount("/", routes![hello])
}
fn main() {
# if false {
rocket().launch();
# }
}
```
Notice that we've separated the _creation_ of the `Rocket` instance from the

View File

@ -205,8 +205,8 @@ async fn assets(asset: PathBuf, assets_dir: State<'_, AssetsDir>) -> Option<Name
NamedFile::open(Path::new(&assets_dir.0).join(asset)).await.ok()
}
fn main() {
# if false {
#[rocket::launch]
fn rocket() -> rocket::Rocket {
rocket::ignite()
.mount("/", routes![assets])
.attach(AdHoc::on_attach("Assets Config", |mut rocket| async {
@ -217,8 +217,6 @@ fn main() {
Ok(rocket.manage(AssetsDir(assets_dir)))
}))
.launch();
# }
}
```
@ -275,7 +273,8 @@ let config = Config::build(Environment::Staging)
# /*
rocket::custom(config)
.mount("/", routes![/* .. */])
.launch();
.launch()
.await;
# */
```