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