mirror of https://github.com/rwf2/Rocket.git
Use launch-inferred '_' in most example code.
This commit is contained in:
parent
c924ff7591
commit
fd8c9ce795
|
@ -18,7 +18,7 @@ fn hello(name: &str, age: u8) -> String {
|
|||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/hello", routes![hello])
|
||||
}
|
||||
```
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
//! struct LogsDbConn(diesel::SqliteConnection);
|
||||
//!
|
||||
//! #[launch]
|
||||
//! fn rocket() -> rocket::Rocket {
|
||||
//! fn rocket() -> _ {
|
||||
//! rocket::build().attach(LogsDbConn::fairing())
|
||||
//! }
|
||||
//! # } fn main() {}
|
||||
|
|
|
@ -203,7 +203,7 @@ impl std::ops::BitOr for Options {
|
|||
/// use rocket_contrib::serve::StaticFiles;
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().mount("/public", StaticFiles::from("/static"))
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -227,7 +227,7 @@ impl std::ops::BitOr for Options {
|
|||
/// use rocket_contrib::serve::{StaticFiles, crate_relative};
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().mount("/", StaticFiles::from(crate_relative!("static")))
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -263,7 +263,7 @@ impl StaticFiles {
|
|||
/// use rocket_contrib::serve::StaticFiles;
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().mount("/static", StaticFiles::from("/www/public"))
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -276,7 +276,7 @@ impl StaticFiles {
|
|||
/// use rocket_contrib::serve::StaticFiles;
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().mount("/static", StaticFiles::from("/www/public").rank(30))
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -305,7 +305,7 @@ impl StaticFiles {
|
|||
/// use rocket_contrib::serve::{StaticFiles, Options};
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// let options = Options::Index | Options::DotFiles;
|
||||
/// rocket::build()
|
||||
/// .mount("/static", StaticFiles::from("/www/public"))
|
||||
|
|
|
@ -37,7 +37,7 @@ mod b_inferred {
|
|||
mod c {
|
||||
// non-async launch.
|
||||
#[rocket::launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build()
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ note: this function cannot be `main`
|
|||
error[E0728]: `await` is only allowed inside `async` functions and blocks
|
||||
--> $DIR/async-entry.rs:75:17
|
||||
|
|
||||
74 | fn rocket() -> rocket::Rocket {
|
||||
72 | fn rocket() -> _ {
|
||||
| ------ this is not `async`
|
||||
75 | let _ = rocket::build().launch().await;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
|
||||
|
|
|
@ -102,7 +102,7 @@ error: [note] this function cannot be `main`
|
|||
error[E0728]: `await` is only allowed inside `async` functions and blocks
|
||||
--> $DIR/async-entry.rs:75:17
|
||||
|
|
||||
74 | fn rocket() -> rocket::Rocket {
|
||||
72 | fn rocket() -> _ {
|
||||
| ------ this is not `async`
|
||||
75 | let _ = rocket::build().launch().await;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only allowed inside `async` functions and blocks
|
||||
|
|
|
@ -41,7 +41,7 @@ mod launch_a {
|
|||
|
||||
mod launch_b {
|
||||
#[rocket::launch]
|
||||
async fn rocket() -> rocket::Rocket {
|
||||
async fn rocket() -> _ {
|
||||
let _ = rocket::build().launch().await;
|
||||
"hi".to_string()
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ mod launch_e {
|
|||
|
||||
mod launch_f {
|
||||
#[rocket::launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
let _ = rocket::build().launch().await;
|
||||
rocket::build()
|
||||
}
|
||||
|
|
|
@ -200,7 +200,10 @@ impl AdHoc {
|
|||
/// /* and so on.. */
|
||||
/// }
|
||||
///
|
||||
/// let fairing = AdHoc::config::<Config>();
|
||||
/// #[launch]
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().attach(AdHoc::config::<Config>())
|
||||
/// }
|
||||
/// ```
|
||||
pub fn config<'de, T>() -> AdHoc
|
||||
where T: serde::Deserialize<'de> + Send + Sync + 'static
|
||||
|
|
|
@ -28,7 +28,7 @@ use crate::{Request, Response};
|
|||
/// }
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().mount("/", routes![hello_world])
|
||||
/// # .reconfigure(rocket::Config::debug_default())
|
||||
/// }
|
||||
|
|
|
@ -25,7 +25,7 @@ use super::Client;
|
|||
/// }
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().mount("/", routes![hello_world])
|
||||
/// # .reconfigure(rocket::Config::debug_default())
|
||||
/// }
|
||||
|
|
|
@ -43,8 +43,7 @@
|
|||
//!
|
||||
//! # /*
|
||||
//! #[launch]
|
||||
//! # */
|
||||
//! fn rocket() -> rocket::Rocket {
|
||||
//! fn rocket() -> _ {
|
||||
//! rocket::build().mount("/", routes![hello])
|
||||
//! }
|
||||
//!
|
||||
|
|
|
@ -47,9 +47,11 @@ impl Rocket {
|
|||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # {
|
||||
/// rocket::build()
|
||||
/// # };
|
||||
/// # use rocket::launch;
|
||||
/// #[launch]
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build()
|
||||
/// }
|
||||
/// ```
|
||||
#[track_caller]
|
||||
#[inline(always)]
|
||||
|
@ -177,7 +179,7 @@ impl Rocket {
|
|||
/// }
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().mount("/hello", routes![hi])
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -195,10 +197,11 @@ impl Rocket {
|
|||
/// Outcome::from(req, "Hello!").pin()
|
||||
/// }
|
||||
///
|
||||
/// # let _ = async { // We don't actually want to launch the server in an example.
|
||||
/// rocket::build().mount("/hello", vec![Route::new(Get, "/world", hi)])
|
||||
/// # .launch().await;
|
||||
/// # };
|
||||
/// #[launch]
|
||||
/// fn rocket() -> _ {
|
||||
/// let hi_route = Route::new(Method::Get, "/world", hi);
|
||||
/// rocket::build().mount("/hello", vec![hi_route])
|
||||
/// }
|
||||
/// ```
|
||||
pub fn mount<'a, B, R>(mut self, base: B, routes: R) -> Self
|
||||
where B: TryInto<Origin<'a>> + Clone + Display,
|
||||
|
@ -263,7 +266,7 @@ impl Rocket {
|
|||
/// }
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build().register("/", catchers![internal_error, not_found])
|
||||
/// }
|
||||
/// ```
|
||||
|
@ -322,7 +325,7 @@ impl Rocket {
|
|||
/// }
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build()
|
||||
/// .mount("/", routes![index])
|
||||
/// .manage(MyValue(10))
|
||||
|
@ -350,7 +353,7 @@ impl Rocket {
|
|||
/// use rocket::fairing::AdHoc;
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build()
|
||||
/// .attach(AdHoc::on_liftoff("Liftoff Message", |_| Box::pin(async {
|
||||
/// println!("We have liftoff!");
|
||||
|
@ -372,7 +375,7 @@ impl Rocket {
|
|||
/// use rocket::fairing::AdHoc;
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build()
|
||||
/// .attach(AdHoc::on_liftoff("Print Config", |rocket| Box::pin(async move {
|
||||
/// println!("Rocket launch config: {:?}", rocket.config());
|
||||
|
|
|
@ -43,7 +43,7 @@ use crate::http::Status;
|
|||
/// }
|
||||
///
|
||||
/// #[launch]
|
||||
/// fn rocket() -> rocket::Rocket {
|
||||
/// fn rocket() -> _ {
|
||||
/// rocket::build()
|
||||
/// .mount("/", routes![index, raw_config_value])
|
||||
/// .manage(MyConfig { user_val: "user input".to_string() })
|
||||
|
|
|
@ -103,7 +103,7 @@ async fn run_migrations(rocket: Rocket) -> Rocket {
|
|||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build()
|
||||
.attach(DbConn::fairing())
|
||||
.attach(Template::fairing())
|
||||
|
|
|
@ -53,7 +53,7 @@ And finally, create a skeleton Rocket application to work off of in
|
|||
#[macro_use] extern crate rocket;
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build()
|
||||
}
|
||||
```
|
||||
|
@ -110,7 +110,7 @@ to them. To mount the `index` route, modify the main function so that it reads:
|
|||
# #[get("/")] fn index() { }
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![index])
|
||||
}
|
||||
```
|
||||
|
@ -276,7 +276,7 @@ extension trait. Ensure that the route is mounted at the root path:
|
|||
# #[post("/")] fn upload() {}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![index, upload])
|
||||
}
|
||||
```
|
||||
|
@ -340,7 +340,7 @@ Make sure that the route is mounted at the root path:
|
|||
# #[get("/<id>")] fn retrieve(id: String) {}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![index, upload, retrieve])
|
||||
}
|
||||
```
|
||||
|
|
|
@ -71,7 +71,7 @@ fn index() -> &'static str {
|
|||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![index])
|
||||
}
|
||||
```
|
||||
|
|
|
@ -155,7 +155,7 @@ fn world() -> &'static str {
|
|||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/hello", routes![world])
|
||||
}
|
||||
```
|
||||
|
@ -181,12 +181,10 @@ Running the application, the console shows:
|
|||
|
||||
! tip: You can also return `_` from a `#[launch]` function!
|
||||
|
||||
If you find it more pleasing, `#[launch]` can infer the return type of
|
||||
`Rocket` for you by using `_` as the return type:
|
||||
|
||||
`
|
||||
#[launch] fn rocket() -> _ { /* ... */ }
|
||||
`
|
||||
Special to Rocket's `#[launch]` attribute, the return type of a function
|
||||
decorated with `#[launch]` is automatically inferred when the return type is
|
||||
set to `_`. If you prefer, you can also set the return type explicitly to
|
||||
`Rocket<Build>`.
|
||||
|
||||
If we visit `http://127.0.0.1:8000/hello/world`, we see `Hello, world!`, exactly
|
||||
as we expected.
|
||||
|
|
|
@ -200,7 +200,7 @@ fn user_int(id: isize) { /* ... */ }
|
|||
fn user_str(id: &str) { /* ... */ }
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![user, user_int, user_str])
|
||||
}
|
||||
```
|
||||
|
|
|
@ -291,7 +291,7 @@ use rocket_contrib::databases::diesel;
|
|||
struct LogsDbConn(diesel::SqliteConnection);
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().attach(LogsDbConn::fairing())
|
||||
}
|
||||
```
|
||||
|
|
|
@ -51,7 +51,7 @@ example, the following snippet attached two fairings, `req_fairing` and
|
|||
```rust
|
||||
# use rocket::launch;
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn 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 {}));
|
||||
|
||||
|
|
|
@ -123,7 +123,7 @@ fn hello() -> &'static str {
|
|||
}
|
||||
|
||||
#[launch]
|
||||
fn rocket() -> rocket::Rocket {
|
||||
fn rocket() -> _ {
|
||||
rocket::build().mount("/", routes![hello])
|
||||
}
|
||||
```
|
||||
|
@ -164,7 +164,8 @@ To test our "Hello, world!" application, we create a `Client` for our
|
|||
testing: we _want_ our tests to panic when something goes wrong.
|
||||
|
||||
```rust
|
||||
# fn rocket() -> rocket::Rocket {
|
||||
# #[rocket::launch]
|
||||
# fn rocket() -> _ {
|
||||
# rocket::build().reconfigure(rocket::Config::debug_default())
|
||||
# }
|
||||
# use rocket::local::blocking::Client;
|
||||
|
@ -176,7 +177,8 @@ Then, we create a new `GET /` request and dispatch it, getting back our
|
|||
application's response:
|
||||
|
||||
```rust
|
||||
# fn rocket() -> rocket::Rocket {
|
||||
# #[rocket::launch]
|
||||
# fn rocket() -> _ {
|
||||
# rocket::build().reconfigure(rocket::Config::debug_default())
|
||||
# }
|
||||
# use rocket::local::blocking::Client;
|
||||
|
|
Loading…
Reference in New Issue