2018-06-04 16:06:08 +00:00
|
|
|
#![recursion_limit="256"]
|
2016-03-19 02:05:29 +00:00
|
|
|
|
2020-10-21 11:54:24 +00:00
|
|
|
#![doc(html_root_url = "https://api.rocket.rs/master")]
|
2020-06-11 09:30:14 +00:00
|
|
|
#![doc(html_favicon_url = "https://rocket.rs/images/favicon.ico")]
|
|
|
|
#![doc(html_logo_url = "https://rocket.rs/images/logo-boxed.png")]
|
2020-07-22 19:21:19 +00:00
|
|
|
#![cfg_attr(nightly, feature(doc_cfg))]
|
2021-04-28 08:29:05 +00:00
|
|
|
#![cfg_attr(nightly, feature(decl_macro))]
|
2017-06-11 08:03:59 +00:00
|
|
|
|
2019-06-13 01:48:02 +00:00
|
|
|
#![warn(rust_2018_idioms)]
|
2021-05-24 01:09:43 +00:00
|
|
|
#![warn(missing_docs)]
|
2019-06-13 01:48:02 +00:00
|
|
|
|
2016-10-03 00:52:04 +00:00
|
|
|
//! # Rocket - Core API Documentation
|
2016-09-30 04:44:27 +00:00
|
|
|
//!
|
|
|
|
//! Hello, and welcome to the core Rocket API documentation!
|
|
|
|
//!
|
|
|
|
//! This API documentation is highly technical and is purely a reference.
|
2018-10-06 13:25:17 +00:00
|
|
|
//! There's an [overview] of Rocket on the main site as well as a [full,
|
|
|
|
//! detailed guide]. If you'd like pointers on getting started, see the
|
|
|
|
//! [quickstart] or [getting started] chapters of the guide.
|
2016-09-30 04:44:27 +00:00
|
|
|
//!
|
2020-10-21 11:54:24 +00:00
|
|
|
//! [overview]: https://rocket.rs/master/overview
|
|
|
|
//! [full, detailed guide]: https://rocket.rs/master/guide
|
|
|
|
//! [quickstart]: https://rocket.rs/master/guide/quickstart
|
|
|
|
//! [getting started]: https://rocket.rs/master/guide/getting-started
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
|
|
|
//! ## Usage
|
|
|
|
//!
|
2020-10-22 10:27:04 +00:00
|
|
|
//! Depend on `rocket` in `Rocket.toml`:
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
2018-10-06 13:25:17 +00:00
|
|
|
//! ```toml
|
2016-10-03 00:52:04 +00:00
|
|
|
//! [dependencies]
|
2019-05-13 23:18:48 +00:00
|
|
|
//! rocket = "0.5.0-dev"
|
2016-10-03 00:52:04 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
2021-03-27 21:20:43 +00:00
|
|
|
//! <small>Note that development versions, tagged with `-dev`, are not published
|
2021-03-28 01:25:46 +00:00
|
|
|
//! and need to be specified as [git dependencies].</small>
|
2021-03-27 21:20:43 +00:00
|
|
|
//!
|
|
|
|
//! See the [guide](https://rocket.rs/master/guide) for more information on how
|
|
|
|
//! to write Rocket applications. Here's a simple example to get you started:
|
|
|
|
//!
|
|
|
|
//! [git dependencies]: https://doc.rust-lang.org/cargo/reference/specifying-dependencies.html#specifying-dependencies-from-git-repositories
|
2016-10-18 02:29:58 +00:00
|
|
|
//!
|
2020-06-16 12:01:26 +00:00
|
|
|
//! ```rust,no_run
|
2018-06-28 15:55:15 +00:00
|
|
|
//! #[macro_use] extern crate rocket;
|
2016-10-18 02:29:58 +00:00
|
|
|
//!
|
|
|
|
//! #[get("/")]
|
|
|
|
//! fn hello() -> &'static str {
|
|
|
|
//! "Hello, world!"
|
|
|
|
//! }
|
|
|
|
//!
|
2020-07-22 23:10:02 +00:00
|
|
|
//! #[launch]
|
2020-09-03 05:41:31 +00:00
|
|
|
//! fn rocket() -> _ {
|
2021-04-08 08:07:52 +00:00
|
|
|
//! rocket::build().mount("/", routes![hello])
|
2016-10-18 02:29:58 +00:00
|
|
|
//! }
|
|
|
|
//! ```
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
2020-07-22 19:21:19 +00:00
|
|
|
//! ## Features
|
|
|
|
//!
|
2021-05-22 05:52:52 +00:00
|
|
|
//! To avoid compiling unused dependencies, Rocket gates certain features, all
|
|
|
|
//! of which are disabled by default:
|
2020-09-03 05:41:31 +00:00
|
|
|
//!
|
2021-04-29 12:19:24 +00:00
|
|
|
//! | Feature | Description |
|
|
|
|
//! |-----------|---------------------------------------------------------|
|
|
|
|
//! | `secrets` | Support for authenticated, encrypted [private cookies]. |
|
|
|
|
//! | `tls` | Support for [TLS] encrypted connections. |
|
|
|
|
//! | `json` | Support for [JSON (de)serialization]. |
|
|
|
|
//! | `msgpack` | Support for [MessagePack (de)serialization]. |
|
2021-05-21 21:29:43 +00:00
|
|
|
//! | `uuid` | Support for [UUID value parsing and (de)serialization]. |
|
2020-09-03 05:41:31 +00:00
|
|
|
//!
|
2021-04-29 12:19:24 +00:00
|
|
|
//! Features can be selectively enabled in `Cargo.toml`:
|
2020-07-22 19:21:19 +00:00
|
|
|
//!
|
|
|
|
//! ```toml
|
|
|
|
//! [dependencies]
|
2021-04-29 12:19:24 +00:00
|
|
|
//! rocket = { version = "0.5.0-dev", features = ["secrets", "tls", "json"] }
|
2020-07-22 19:21:19 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
2021-04-29 12:19:24 +00:00
|
|
|
//! [JSON (de)serialization]: crate::serde::json
|
|
|
|
//! [MessagePack (de)serialization]: crate::serde::msgpack
|
2021-05-21 21:29:43 +00:00
|
|
|
//! [UUID value parsing and (de)serialization]: crate::serde::uuid
|
2020-10-21 11:54:24 +00:00
|
|
|
//! [private cookies]: https://rocket.rs/master/guide/requests/#private-cookies
|
|
|
|
//! [TLS]: https://rocket.rs/master/guide/configuration/#tls
|
2020-07-22 19:21:19 +00:00
|
|
|
//!
|
2016-10-03 00:52:04 +00:00
|
|
|
//! ## Configuration
|
|
|
|
//!
|
2021-04-29 12:19:24 +00:00
|
|
|
//! Rocket offers a rich, extensible configuration system built on [Figment]. By
|
|
|
|
//! default, Rocket applications are configured via a `Rocket.toml` file
|
|
|
|
//! and/or `ROCKET_{PARAM}` environment variables, but applications may
|
|
|
|
//! configure their own sources. See the [configuration guide] for full details.
|
2016-10-18 02:29:58 +00:00
|
|
|
//!
|
|
|
|
//! ## Testing
|
|
|
|
//!
|
2018-10-06 13:25:17 +00:00
|
|
|
//! The [`local`] module contains structures that facilitate unit and
|
|
|
|
//! integration testing of a Rocket application. The top-level [`local`] module
|
2021-04-29 12:19:24 +00:00
|
|
|
//! documentation and the [testing guide] include detailed examples.
|
2018-10-06 13:25:17 +00:00
|
|
|
//!
|
2021-04-29 12:19:24 +00:00
|
|
|
//! [configuration guide]: https://rocket.rs/master/guide/configuration/
|
|
|
|
//! [testing guide]: https://rocket.rs/master/guide/testing/#testing
|
|
|
|
//! [Figment]: https://docs.rs/figment
|
2016-10-04 00:09:13 +00:00
|
|
|
|
2020-09-03 05:41:31 +00:00
|
|
|
/// These are public dependencies! Update docs if these are changed, especially
|
|
|
|
/// figment's version number in docs.
|
2021-04-28 09:01:35 +00:00
|
|
|
#[doc(hidden)] pub use yansi;
|
|
|
|
#[doc(hidden)] pub use async_stream;
|
2020-02-03 08:30:22 +00:00
|
|
|
pub use futures;
|
|
|
|
pub use tokio;
|
2020-09-03 05:41:31 +00:00
|
|
|
pub use figment;
|
2020-02-03 08:30:22 +00:00
|
|
|
|
UTF-8 routes. Forms revamp. Temp files. Capped.
So. Many. Changes.
This is an insane commit: simultaneously one of the best (because of all
the wonderful improvements!) and one of the worst (because it is just
massive) in the project's history.
Routing:
* All UTF-8 characters are accepted everywhere in route paths. (#998)
* `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]`
becomes `#[route(GET, uri = "..")]`.
Forms Revamp
* All form related types now reside in a new `form` module.
* Multipart forms are supported. (resolves #106)
* Collections are supported in forms and queries. (resolves #205)
* Nested structures in forms and queries are supported. (resolves #313)
* Form fields can be ad-hoc validated with `#[field(validate = expr)]`.
* `FromFormValue` is now `FromFormField`, blanket implements `FromForm`.
* Form field values are always percent-decoded apriori.
Temporary Files
* A new `TempFile` data and form guard allows streaming data directly to a
file which can then be persisted.
* A new `temp_dir` config parameter specifies where to store `TempFile`.
* The limits `file` and `file/$ext`, where `$ext` is the file extension,
determines the data limit for a `TempFile`.
Capped
* A new `Capped` type is used to indicate when data has been truncated due to
incoming data limits. It allows checking whether data is complete or
truncated.
* `DataStream` methods return `Capped` types.
* `DataStream` API has been revamped to account for `Capped` types.
* Several `Capped<T>` types implement `FromData`, `FromForm`.
* HTTP 413 (Payload Too Large) errors are now returned when data limits are
exceeded. (resolves #972)
Hierarchical Limits
* Data limits are now hierarchical, delimited with `/`. A limit of `a/b/c`
falls back to `a/b` then `a`.
Core
* `&RawStr` no longer implements `FromParam`.
* `&str` implements `FromParam`, `FromData`, `FromForm`.
* `FromTransformedData` was removed.
* `FromData` gained a lifetime for use with request-local data.
* The default error HTML is more compact.
* `&Config` is a request guard.
* The `DataStream` interface was entirely revamped.
* `State` is only exported via `rocket::State`.
* A `request::local_cache!()` macro was added for storing values in
request-local cache without consideration for type uniqueness by using a
locally generated anonymous type.
* `Request::get_param()` is now `Request::param()`.
* `Request::get_segments()` is now `Request::segments()`, takes a range.
* `Request::get_query_value()` is now `Request::query_value()`, can parse any
`FromForm` including sequences.
* `std::io::Error` implements `Responder` like `Debug<std::io::Error>`.
* `(Status, R)` where `R: Responder` implements `Responder` by overriding the
`Status` of `R`.
* The name of a route is printed first during route matching.
* `FlashMessage` now only has one lifetime generic.
HTTP
* `RawStr` implements `serde::{Serialize, Deserialize}`.
* `RawStr` implements _many_ more methods, in particular, those related to the
`Pattern` API.
* `RawStr::from_str()` is now `RawStr::new()`.
* `RawStr::url_decode()` and `RawStr::url_decode_lossy()` only allocate as
necessary, return `Cow`.
* `Status` implements `Default` with `Status::Ok`.
* `Status` implements `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`.
* Authority and origin part of `Absolute` can be modified with new
`Absolute::{with,set}_authority()`, `Absolute::{with,set}_origin()` methods.
* `Origin::segments()` was removed in favor of methods split into query and
path parts and into raw and decoded versions.
* The `Segments` iterator is smarter, returns decoded `&str` items.
* `Segments::into_path_buf()` is now `Segments::to_path_buf()`.
* A new `QuerySegments` is the analogous query segment iterator.
* Once set, `expires` on private cookies is not overwritten. (resolves #1506)
* `Origin::path()` and `Origin::query()` return `&RawStr`, not `&str`.
Codegen
* Preserve more spans in `uri!` macro.
* Preserve spans `FromForm` field types.
* All dynamic parameters in a query string must typecheck as `FromForm`.
* `FromFormValue` derive removed; `FromFormField` added.
* The `form` `FromForm` and `FromFormField` field attribute is now named
`field`. `#[form(field = ..)]` is now `#[field(name = ..)]`.
Contrib
* `Json` implements `FromForm`.
* `MsgPack` implements `FromForm`.
* The `json!` macro is exported as `rocket_contrib::json::json!`.
* Added clarifying docs to `StaticFiles`.
Examples
* `form_validation` and `form_kitchen_sink` removed in favor of `forms`.
* The `hello_world` example uses unicode in paths.
* The `json` example only allocates as necessary.
Internal
* Codegen uses new `exports` module with the following conventions:
- Locals starts with `__` and are lowercased.
- Rocket modules start with `_` and are lowercased.
- `std` types start with `_` and are titlecased.
- Rocket types are titlecased.
* A `header` module was added to `http`, contains header types.
* `SAFETY` is used as doc-string keyword for `unsafe` related comments.
* The `Uri` parser no longer recognizes Rocket route URIs.
2020-10-30 03:50:06 +00:00
|
|
|
#[doc(hidden)]
|
2021-04-24 02:13:30 +00:00
|
|
|
#[macro_use] pub mod log;
|
2019-09-11 01:04:34 +00:00
|
|
|
#[macro_use] pub mod outcome;
|
UTF-8 routes. Forms revamp. Temp files. Capped.
So. Many. Changes.
This is an insane commit: simultaneously one of the best (because of all
the wonderful improvements!) and one of the worst (because it is just
massive) in the project's history.
Routing:
* All UTF-8 characters are accepted everywhere in route paths. (#998)
* `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]`
becomes `#[route(GET, uri = "..")]`.
Forms Revamp
* All form related types now reside in a new `form` module.
* Multipart forms are supported. (resolves #106)
* Collections are supported in forms and queries. (resolves #205)
* Nested structures in forms and queries are supported. (resolves #313)
* Form fields can be ad-hoc validated with `#[field(validate = expr)]`.
* `FromFormValue` is now `FromFormField`, blanket implements `FromForm`.
* Form field values are always percent-decoded apriori.
Temporary Files
* A new `TempFile` data and form guard allows streaming data directly to a
file which can then be persisted.
* A new `temp_dir` config parameter specifies where to store `TempFile`.
* The limits `file` and `file/$ext`, where `$ext` is the file extension,
determines the data limit for a `TempFile`.
Capped
* A new `Capped` type is used to indicate when data has been truncated due to
incoming data limits. It allows checking whether data is complete or
truncated.
* `DataStream` methods return `Capped` types.
* `DataStream` API has been revamped to account for `Capped` types.
* Several `Capped<T>` types implement `FromData`, `FromForm`.
* HTTP 413 (Payload Too Large) errors are now returned when data limits are
exceeded. (resolves #972)
Hierarchical Limits
* Data limits are now hierarchical, delimited with `/`. A limit of `a/b/c`
falls back to `a/b` then `a`.
Core
* `&RawStr` no longer implements `FromParam`.
* `&str` implements `FromParam`, `FromData`, `FromForm`.
* `FromTransformedData` was removed.
* `FromData` gained a lifetime for use with request-local data.
* The default error HTML is more compact.
* `&Config` is a request guard.
* The `DataStream` interface was entirely revamped.
* `State` is only exported via `rocket::State`.
* A `request::local_cache!()` macro was added for storing values in
request-local cache without consideration for type uniqueness by using a
locally generated anonymous type.
* `Request::get_param()` is now `Request::param()`.
* `Request::get_segments()` is now `Request::segments()`, takes a range.
* `Request::get_query_value()` is now `Request::query_value()`, can parse any
`FromForm` including sequences.
* `std::io::Error` implements `Responder` like `Debug<std::io::Error>`.
* `(Status, R)` where `R: Responder` implements `Responder` by overriding the
`Status` of `R`.
* The name of a route is printed first during route matching.
* `FlashMessage` now only has one lifetime generic.
HTTP
* `RawStr` implements `serde::{Serialize, Deserialize}`.
* `RawStr` implements _many_ more methods, in particular, those related to the
`Pattern` API.
* `RawStr::from_str()` is now `RawStr::new()`.
* `RawStr::url_decode()` and `RawStr::url_decode_lossy()` only allocate as
necessary, return `Cow`.
* `Status` implements `Default` with `Status::Ok`.
* `Status` implements `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`.
* Authority and origin part of `Absolute` can be modified with new
`Absolute::{with,set}_authority()`, `Absolute::{with,set}_origin()` methods.
* `Origin::segments()` was removed in favor of methods split into query and
path parts and into raw and decoded versions.
* The `Segments` iterator is smarter, returns decoded `&str` items.
* `Segments::into_path_buf()` is now `Segments::to_path_buf()`.
* A new `QuerySegments` is the analogous query segment iterator.
* Once set, `expires` on private cookies is not overwritten. (resolves #1506)
* `Origin::path()` and `Origin::query()` return `&RawStr`, not `&str`.
Codegen
* Preserve more spans in `uri!` macro.
* Preserve spans `FromForm` field types.
* All dynamic parameters in a query string must typecheck as `FromForm`.
* `FromFormValue` derive removed; `FromFormField` added.
* The `form` `FromForm` and `FromFormField` field attribute is now named
`field`. `#[form(field = ..)]` is now `#[field(name = ..)]`.
Contrib
* `Json` implements `FromForm`.
* `MsgPack` implements `FromForm`.
* The `json!` macro is exported as `rocket_contrib::json::json!`.
* Added clarifying docs to `StaticFiles`.
Examples
* `form_validation` and `form_kitchen_sink` removed in favor of `forms`.
* The `hello_world` example uses unicode in paths.
* The `json` example only allocates as necessary.
Internal
* Codegen uses new `exports` module with the following conventions:
- Locals starts with `__` and are lowercased.
- Rocket modules start with `_` and are lowercased.
- `std` types start with `_` and are titlecased.
- Rocket types are titlecased.
* A `header` module was added to `http`, contains header types.
* `SAFETY` is used as doc-string keyword for `unsafe` related comments.
* The `Uri` parser no longer recognizes Rocket route URIs.
2020-10-30 03:50:06 +00:00
|
|
|
#[macro_use] pub mod data;
|
Introduce sentinels: auto-discovered launch abort.
Sentinels resolve a long-standing usability and functional correctness
issue in Rocket: starting an application with guards and/or responders
that depend on state that isn't available. The canonical example is the
'State' guard. Prior to this commit, an application with routes that
queried unmanaged state via 'State' would fail at runtime. With this
commit, the application refuses to launch with a detailed error message.
The 'Sentinel' docs explains it as:
A sentinel, automatically run on ignition, can trigger a launch
abort should an instance fail to meet arbitrary conditions. Every
type that appears in a mounted route's type signature is eligible to
be a sentinel. Of these, those that implement 'Sentinel' have their
'abort()' method invoked automatically, immediately after ignition,
once for each unique type. Sentinels inspect the finalized instance
of 'Rocket' and can trigger a launch abort by returning 'true'.
The following types are now sentinels:
* 'contrib::databases::Connection' (any '#[database]' type)
* 'contrib::templates::Metadata'
* 'contrib::templates::Template'
* 'core::State'
The following are "specialized" sentinels, which allow sentinel
discovery even through type aliases:
* 'Option<T>', 'Debug<T>' if 'T: Sentinel'
* 'Result<T, E>', 'Either<T, E>' if 'T: Sentinel', 'E: Sentinel'
Closes #464.
2021-04-16 08:23:15 +00:00
|
|
|
#[doc(hidden)] pub mod sentinel;
|
2017-06-06 20:41:04 +00:00
|
|
|
pub mod local;
|
2016-08-24 08:30:09 +00:00
|
|
|
pub mod request;
|
|
|
|
pub mod response;
|
2016-10-15 01:57:36 +00:00
|
|
|
pub mod config;
|
UTF-8 routes. Forms revamp. Temp files. Capped.
So. Many. Changes.
This is an insane commit: simultaneously one of the best (because of all
the wonderful improvements!) and one of the worst (because it is just
massive) in the project's history.
Routing:
* All UTF-8 characters are accepted everywhere in route paths. (#998)
* `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]`
becomes `#[route(GET, uri = "..")]`.
Forms Revamp
* All form related types now reside in a new `form` module.
* Multipart forms are supported. (resolves #106)
* Collections are supported in forms and queries. (resolves #205)
* Nested structures in forms and queries are supported. (resolves #313)
* Form fields can be ad-hoc validated with `#[field(validate = expr)]`.
* `FromFormValue` is now `FromFormField`, blanket implements `FromForm`.
* Form field values are always percent-decoded apriori.
Temporary Files
* A new `TempFile` data and form guard allows streaming data directly to a
file which can then be persisted.
* A new `temp_dir` config parameter specifies where to store `TempFile`.
* The limits `file` and `file/$ext`, where `$ext` is the file extension,
determines the data limit for a `TempFile`.
Capped
* A new `Capped` type is used to indicate when data has been truncated due to
incoming data limits. It allows checking whether data is complete or
truncated.
* `DataStream` methods return `Capped` types.
* `DataStream` API has been revamped to account for `Capped` types.
* Several `Capped<T>` types implement `FromData`, `FromForm`.
* HTTP 413 (Payload Too Large) errors are now returned when data limits are
exceeded. (resolves #972)
Hierarchical Limits
* Data limits are now hierarchical, delimited with `/`. A limit of `a/b/c`
falls back to `a/b` then `a`.
Core
* `&RawStr` no longer implements `FromParam`.
* `&str` implements `FromParam`, `FromData`, `FromForm`.
* `FromTransformedData` was removed.
* `FromData` gained a lifetime for use with request-local data.
* The default error HTML is more compact.
* `&Config` is a request guard.
* The `DataStream` interface was entirely revamped.
* `State` is only exported via `rocket::State`.
* A `request::local_cache!()` macro was added for storing values in
request-local cache without consideration for type uniqueness by using a
locally generated anonymous type.
* `Request::get_param()` is now `Request::param()`.
* `Request::get_segments()` is now `Request::segments()`, takes a range.
* `Request::get_query_value()` is now `Request::query_value()`, can parse any
`FromForm` including sequences.
* `std::io::Error` implements `Responder` like `Debug<std::io::Error>`.
* `(Status, R)` where `R: Responder` implements `Responder` by overriding the
`Status` of `R`.
* The name of a route is printed first during route matching.
* `FlashMessage` now only has one lifetime generic.
HTTP
* `RawStr` implements `serde::{Serialize, Deserialize}`.
* `RawStr` implements _many_ more methods, in particular, those related to the
`Pattern` API.
* `RawStr::from_str()` is now `RawStr::new()`.
* `RawStr::url_decode()` and `RawStr::url_decode_lossy()` only allocate as
necessary, return `Cow`.
* `Status` implements `Default` with `Status::Ok`.
* `Status` implements `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`.
* Authority and origin part of `Absolute` can be modified with new
`Absolute::{with,set}_authority()`, `Absolute::{with,set}_origin()` methods.
* `Origin::segments()` was removed in favor of methods split into query and
path parts and into raw and decoded versions.
* The `Segments` iterator is smarter, returns decoded `&str` items.
* `Segments::into_path_buf()` is now `Segments::to_path_buf()`.
* A new `QuerySegments` is the analogous query segment iterator.
* Once set, `expires` on private cookies is not overwritten. (resolves #1506)
* `Origin::path()` and `Origin::query()` return `&RawStr`, not `&str`.
Codegen
* Preserve more spans in `uri!` macro.
* Preserve spans `FromForm` field types.
* All dynamic parameters in a query string must typecheck as `FromForm`.
* `FromFormValue` derive removed; `FromFormField` added.
* The `form` `FromForm` and `FromFormField` field attribute is now named
`field`. `#[form(field = ..)]` is now `#[field(name = ..)]`.
Contrib
* `Json` implements `FromForm`.
* `MsgPack` implements `FromForm`.
* The `json!` macro is exported as `rocket_contrib::json::json!`.
* Added clarifying docs to `StaticFiles`.
Examples
* `form_validation` and `form_kitchen_sink` removed in favor of `forms`.
* The `hello_world` example uses unicode in paths.
* The `json` example only allocates as necessary.
Internal
* Codegen uses new `exports` module with the following conventions:
- Locals starts with `__` and are lowercased.
- Rocket modules start with `_` and are lowercased.
- `std` types start with `_` and are titlecased.
- Rocket types are titlecased.
* A `header` module was added to `http`, contains header types.
* `SAFETY` is used as doc-string keyword for `unsafe` related comments.
* The `Uri` parser no longer recognizes Rocket route URIs.
2020-10-30 03:50:06 +00:00
|
|
|
pub mod form;
|
2017-04-20 20:43:01 +00:00
|
|
|
pub mod fairing;
|
2017-06-12 22:08:34 +00:00
|
|
|
pub mod error;
|
2020-07-30 06:07:22 +00:00
|
|
|
pub mod catcher;
|
2021-04-14 01:58:05 +00:00
|
|
|
pub mod route;
|
2021-04-29 12:19:24 +00:00
|
|
|
pub mod serde;
|
2021-05-22 05:52:52 +00:00
|
|
|
pub mod shield;
|
2021-05-22 17:55:59 +00:00
|
|
|
pub mod fs;
|
2016-03-12 18:45:19 +00:00
|
|
|
|
2018-06-07 13:34:47 +00:00
|
|
|
// Reexport of HTTP everything.
|
|
|
|
pub mod http {
|
2018-08-16 02:55:34 +00:00
|
|
|
//! Types that map to concepts in HTTP.
|
|
|
|
//!
|
|
|
|
//! This module exports types that map to HTTP concepts or to the underlying
|
|
|
|
//! HTTP library when needed.
|
|
|
|
|
2018-06-07 13:34:47 +00:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use rocket_http::*;
|
2021-03-09 02:18:15 +00:00
|
|
|
|
|
|
|
#[doc(inline)]
|
|
|
|
pub use crate::cookies::*;
|
2018-06-07 13:34:47 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 09:01:35 +00:00
|
|
|
/// TODO: We need a futures mod or something.
|
|
|
|
mod trip_wire;
|
2020-07-22 23:10:02 +00:00
|
|
|
mod shutdown;
|
2020-10-23 00:37:05 +00:00
|
|
|
mod server;
|
2018-10-23 20:22:26 +00:00
|
|
|
mod ext;
|
UTF-8 routes. Forms revamp. Temp files. Capped.
So. Many. Changes.
This is an insane commit: simultaneously one of the best (because of all
the wonderful improvements!) and one of the worst (because it is just
massive) in the project's history.
Routing:
* All UTF-8 characters are accepted everywhere in route paths. (#998)
* `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]`
becomes `#[route(GET, uri = "..")]`.
Forms Revamp
* All form related types now reside in a new `form` module.
* Multipart forms are supported. (resolves #106)
* Collections are supported in forms and queries. (resolves #205)
* Nested structures in forms and queries are supported. (resolves #313)
* Form fields can be ad-hoc validated with `#[field(validate = expr)]`.
* `FromFormValue` is now `FromFormField`, blanket implements `FromForm`.
* Form field values are always percent-decoded apriori.
Temporary Files
* A new `TempFile` data and form guard allows streaming data directly to a
file which can then be persisted.
* A new `temp_dir` config parameter specifies where to store `TempFile`.
* The limits `file` and `file/$ext`, where `$ext` is the file extension,
determines the data limit for a `TempFile`.
Capped
* A new `Capped` type is used to indicate when data has been truncated due to
incoming data limits. It allows checking whether data is complete or
truncated.
* `DataStream` methods return `Capped` types.
* `DataStream` API has been revamped to account for `Capped` types.
* Several `Capped<T>` types implement `FromData`, `FromForm`.
* HTTP 413 (Payload Too Large) errors are now returned when data limits are
exceeded. (resolves #972)
Hierarchical Limits
* Data limits are now hierarchical, delimited with `/`. A limit of `a/b/c`
falls back to `a/b` then `a`.
Core
* `&RawStr` no longer implements `FromParam`.
* `&str` implements `FromParam`, `FromData`, `FromForm`.
* `FromTransformedData` was removed.
* `FromData` gained a lifetime for use with request-local data.
* The default error HTML is more compact.
* `&Config` is a request guard.
* The `DataStream` interface was entirely revamped.
* `State` is only exported via `rocket::State`.
* A `request::local_cache!()` macro was added for storing values in
request-local cache without consideration for type uniqueness by using a
locally generated anonymous type.
* `Request::get_param()` is now `Request::param()`.
* `Request::get_segments()` is now `Request::segments()`, takes a range.
* `Request::get_query_value()` is now `Request::query_value()`, can parse any
`FromForm` including sequences.
* `std::io::Error` implements `Responder` like `Debug<std::io::Error>`.
* `(Status, R)` where `R: Responder` implements `Responder` by overriding the
`Status` of `R`.
* The name of a route is printed first during route matching.
* `FlashMessage` now only has one lifetime generic.
HTTP
* `RawStr` implements `serde::{Serialize, Deserialize}`.
* `RawStr` implements _many_ more methods, in particular, those related to the
`Pattern` API.
* `RawStr::from_str()` is now `RawStr::new()`.
* `RawStr::url_decode()` and `RawStr::url_decode_lossy()` only allocate as
necessary, return `Cow`.
* `Status` implements `Default` with `Status::Ok`.
* `Status` implements `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`.
* Authority and origin part of `Absolute` can be modified with new
`Absolute::{with,set}_authority()`, `Absolute::{with,set}_origin()` methods.
* `Origin::segments()` was removed in favor of methods split into query and
path parts and into raw and decoded versions.
* The `Segments` iterator is smarter, returns decoded `&str` items.
* `Segments::into_path_buf()` is now `Segments::to_path_buf()`.
* A new `QuerySegments` is the analogous query segment iterator.
* Once set, `expires` on private cookies is not overwritten. (resolves #1506)
* `Origin::path()` and `Origin::query()` return `&RawStr`, not `&str`.
Codegen
* Preserve more spans in `uri!` macro.
* Preserve spans `FromForm` field types.
* All dynamic parameters in a query string must typecheck as `FromForm`.
* `FromFormValue` derive removed; `FromFormField` added.
* The `form` `FromForm` and `FromFormField` field attribute is now named
`field`. `#[form(field = ..)]` is now `#[field(name = ..)]`.
Contrib
* `Json` implements `FromForm`.
* `MsgPack` implements `FromForm`.
* The `json!` macro is exported as `rocket_contrib::json::json!`.
* Added clarifying docs to `StaticFiles`.
Examples
* `form_validation` and `form_kitchen_sink` removed in favor of `forms`.
* The `hello_world` example uses unicode in paths.
* The `json` example only allocates as necessary.
Internal
* Codegen uses new `exports` module with the following conventions:
- Locals starts with `__` and are lowercased.
- Rocket modules start with `_` and are lowercased.
- `std` types start with `_` and are titlecased.
- Rocket types are titlecased.
* A `header` module was added to `http`, contains header types.
* `SAFETY` is used as doc-string keyword for `unsafe` related comments.
* The `Uri` parser no longer recognizes Rocket route URIs.
2020-10-30 03:50:06 +00:00
|
|
|
mod state;
|
2021-03-09 02:18:15 +00:00
|
|
|
mod cookies;
|
2021-04-14 01:58:05 +00:00
|
|
|
mod rocket;
|
|
|
|
mod router;
|
|
|
|
mod phase;
|
2016-04-02 07:51:40 +00:00
|
|
|
|
2019-06-13 01:48:02 +00:00
|
|
|
#[doc(inline)] pub use crate::response::Response;
|
|
|
|
#[doc(inline)] pub use crate::data::Data;
|
|
|
|
#[doc(inline)] pub use crate::config::Config;
|
2020-07-30 06:07:22 +00:00
|
|
|
#[doc(inline)] pub use crate::catcher::Catcher;
|
2021-04-14 01:58:05 +00:00
|
|
|
#[doc(inline)] pub use crate::route::Route;
|
2021-03-30 04:58:18 +00:00
|
|
|
#[doc(hidden)] pub use either::Either;
|
Introduce statically-enforced 'Rocket' phasing.
The core 'Rocket' type is parameterized: 'Rocket<P: Phase>', where
'Phase' is a newly introduced, sealed marker trait. The trait is
implemented by three new marker types representing the three launch
phases: 'Build', 'Ignite', and 'Orbit'. Progression through these three
phases, in order, is enforced, as are the invariants guaranteed by each
phase. In particular, an instance of 'Rocket' is guaranteed to be in its
final configuration after the 'Build' phase and represent a running
local or public server in the 'Orbit' phase. The 'Ignite' phase serves
as an intermediate, enabling inspection of a finalized but stationary
instance. Transition between phases validates the invariants required
by the transition.
All APIs have been adjusted appropriately, requiring either an instance
of 'Rocket' in a particular phase ('Rocket<Build>', 'Rocket<Ignite>', or
'Rocket<Orbit>') or operating generically on a 'Rocket<P>'.
Documentation is also updated and substantially improved to mention
required and guaranteed invariants.
Additionally, this commit makes the following relevant changes:
* 'Rocket::ignite()' is now a public interface.
* 'Rocket::{build,custom}' methods can no longer panic.
* 'Launch' fairings are now 'ignite' fairings.
* 'Liftoff' fairings are always run, even in local mode.
* All 'ignite' fairings run concurrently at ignition.
* Launch logging occurs on launch, not any point prior.
* Launch log messages have improved formatting.
* A new launch error kind, 'Config', was added.
* A 'fairing::Result' type alias was introduced.
* 'Shutdown::shutdown()' is now 'Shutdown::notify()'.
Some internal changes were also introduced:
* Fairing 'Info' name for 'Templates' is now 'Templating'.
* Shutdown is implemented using 'tokio::sync::Notify'.
* 'Client::debug()' is used nearly universally in tests.
Resolves #1154.
Resolves #1136.
2021-04-14 02:26:45 +00:00
|
|
|
#[doc(inline)] pub use phase::{Phase, Build, Ignite, Orbit};
|
|
|
|
#[doc(inline)] pub use error::Error;
|
Introduce sentinels: auto-discovered launch abort.
Sentinels resolve a long-standing usability and functional correctness
issue in Rocket: starting an application with guards and/or responders
that depend on state that isn't available. The canonical example is the
'State' guard. Prior to this commit, an application with routes that
queried unmanaged state via 'State' would fail at runtime. With this
commit, the application refuses to launch with a detailed error message.
The 'Sentinel' docs explains it as:
A sentinel, automatically run on ignition, can trigger a launch
abort should an instance fail to meet arbitrary conditions. Every
type that appears in a mounted route's type signature is eligible to
be a sentinel. Of these, those that implement 'Sentinel' have their
'abort()' method invoked automatically, immediately after ignition,
once for each unique type. Sentinels inspect the finalized instance
of 'Rocket' and can trigger a launch abort by returning 'true'.
The following types are now sentinels:
* 'contrib::databases::Connection' (any '#[database]' type)
* 'contrib::templates::Metadata'
* 'contrib::templates::Template'
* 'core::State'
The following are "specialized" sentinels, which allow sentinel
discovery even through type aliases:
* 'Option<T>', 'Debug<T>' if 'T: Sentinel'
* 'Result<T, E>', 'Either<T, E>' if 'T: Sentinel', 'E: Sentinel'
Closes #464.
2021-04-16 08:23:15 +00:00
|
|
|
#[doc(inline)] pub use sentinel::Sentinel;
|
2021-04-28 08:41:13 +00:00
|
|
|
#[doc(inline)] pub use rocket_codegen::*;
|
2020-10-22 10:27:04 +00:00
|
|
|
pub use crate::rocket::Rocket;
|
Introduce statically-enforced 'Rocket' phasing.
The core 'Rocket' type is parameterized: 'Rocket<P: Phase>', where
'Phase' is a newly introduced, sealed marker trait. The trait is
implemented by three new marker types representing the three launch
phases: 'Build', 'Ignite', and 'Orbit'. Progression through these three
phases, in order, is enforced, as are the invariants guaranteed by each
phase. In particular, an instance of 'Rocket' is guaranteed to be in its
final configuration after the 'Build' phase and represent a running
local or public server in the 'Orbit' phase. The 'Ignite' phase serves
as an intermediate, enabling inspection of a finalized but stationary
instance. Transition between phases validates the invariants required
by the transition.
All APIs have been adjusted appropriately, requiring either an instance
of 'Rocket' in a particular phase ('Rocket<Build>', 'Rocket<Ignite>', or
'Rocket<Orbit>') or operating generically on a 'Rocket<P>'.
Documentation is also updated and substantially improved to mention
required and guaranteed invariants.
Additionally, this commit makes the following relevant changes:
* 'Rocket::ignite()' is now a public interface.
* 'Rocket::{build,custom}' methods can no longer panic.
* 'Launch' fairings are now 'ignite' fairings.
* 'Liftoff' fairings are always run, even in local mode.
* All 'ignite' fairings run concurrently at ignition.
* Launch logging occurs on launch, not any point prior.
* Launch log messages have improved formatting.
* A new launch error kind, 'Config', was added.
* A 'fairing::Result' type alias was introduced.
* 'Shutdown::shutdown()' is now 'Shutdown::notify()'.
Some internal changes were also introduced:
* Fairing 'Info' name for 'Templates' is now 'Templating'.
* Shutdown is implemented using 'tokio::sync::Notify'.
* 'Client::debug()' is used nearly universally in tests.
Resolves #1154.
Resolves #1136.
2021-04-14 02:26:45 +00:00
|
|
|
pub use crate::request::Request;
|
2020-07-22 23:10:02 +00:00
|
|
|
pub use crate::shutdown::Shutdown;
|
UTF-8 routes. Forms revamp. Temp files. Capped.
So. Many. Changes.
This is an insane commit: simultaneously one of the best (because of all
the wonderful improvements!) and one of the worst (because it is just
massive) in the project's history.
Routing:
* All UTF-8 characters are accepted everywhere in route paths. (#998)
* `path` is now `uri` in `route` attribute: `#[route(GET, path = "..")]`
becomes `#[route(GET, uri = "..")]`.
Forms Revamp
* All form related types now reside in a new `form` module.
* Multipart forms are supported. (resolves #106)
* Collections are supported in forms and queries. (resolves #205)
* Nested structures in forms and queries are supported. (resolves #313)
* Form fields can be ad-hoc validated with `#[field(validate = expr)]`.
* `FromFormValue` is now `FromFormField`, blanket implements `FromForm`.
* Form field values are always percent-decoded apriori.
Temporary Files
* A new `TempFile` data and form guard allows streaming data directly to a
file which can then be persisted.
* A new `temp_dir` config parameter specifies where to store `TempFile`.
* The limits `file` and `file/$ext`, where `$ext` is the file extension,
determines the data limit for a `TempFile`.
Capped
* A new `Capped` type is used to indicate when data has been truncated due to
incoming data limits. It allows checking whether data is complete or
truncated.
* `DataStream` methods return `Capped` types.
* `DataStream` API has been revamped to account for `Capped` types.
* Several `Capped<T>` types implement `FromData`, `FromForm`.
* HTTP 413 (Payload Too Large) errors are now returned when data limits are
exceeded. (resolves #972)
Hierarchical Limits
* Data limits are now hierarchical, delimited with `/`. A limit of `a/b/c`
falls back to `a/b` then `a`.
Core
* `&RawStr` no longer implements `FromParam`.
* `&str` implements `FromParam`, `FromData`, `FromForm`.
* `FromTransformedData` was removed.
* `FromData` gained a lifetime for use with request-local data.
* The default error HTML is more compact.
* `&Config` is a request guard.
* The `DataStream` interface was entirely revamped.
* `State` is only exported via `rocket::State`.
* A `request::local_cache!()` macro was added for storing values in
request-local cache without consideration for type uniqueness by using a
locally generated anonymous type.
* `Request::get_param()` is now `Request::param()`.
* `Request::get_segments()` is now `Request::segments()`, takes a range.
* `Request::get_query_value()` is now `Request::query_value()`, can parse any
`FromForm` including sequences.
* `std::io::Error` implements `Responder` like `Debug<std::io::Error>`.
* `(Status, R)` where `R: Responder` implements `Responder` by overriding the
`Status` of `R`.
* The name of a route is printed first during route matching.
* `FlashMessage` now only has one lifetime generic.
HTTP
* `RawStr` implements `serde::{Serialize, Deserialize}`.
* `RawStr` implements _many_ more methods, in particular, those related to the
`Pattern` API.
* `RawStr::from_str()` is now `RawStr::new()`.
* `RawStr::url_decode()` and `RawStr::url_decode_lossy()` only allocate as
necessary, return `Cow`.
* `Status` implements `Default` with `Status::Ok`.
* `Status` implements `PartialEq`, `Eq`, `Hash`, `PartialOrd`, `Ord`.
* Authority and origin part of `Absolute` can be modified with new
`Absolute::{with,set}_authority()`, `Absolute::{with,set}_origin()` methods.
* `Origin::segments()` was removed in favor of methods split into query and
path parts and into raw and decoded versions.
* The `Segments` iterator is smarter, returns decoded `&str` items.
* `Segments::into_path_buf()` is now `Segments::to_path_buf()`.
* A new `QuerySegments` is the analogous query segment iterator.
* Once set, `expires` on private cookies is not overwritten. (resolves #1506)
* `Origin::path()` and `Origin::query()` return `&RawStr`, not `&str`.
Codegen
* Preserve more spans in `uri!` macro.
* Preserve spans `FromForm` field types.
* All dynamic parameters in a query string must typecheck as `FromForm`.
* `FromFormValue` derive removed; `FromFormField` added.
* The `form` `FromForm` and `FromFormField` field attribute is now named
`field`. `#[form(field = ..)]` is now `#[field(name = ..)]`.
Contrib
* `Json` implements `FromForm`.
* `MsgPack` implements `FromForm`.
* The `json!` macro is exported as `rocket_contrib::json::json!`.
* Added clarifying docs to `StaticFiles`.
Examples
* `form_validation` and `form_kitchen_sink` removed in favor of `forms`.
* The `hello_world` example uses unicode in paths.
* The `json` example only allocates as necessary.
Internal
* Codegen uses new `exports` module with the following conventions:
- Locals starts with `__` and are lowercased.
- Rocket modules start with `_` and are lowercased.
- `std` types start with `_` and are titlecased.
- Rocket types are titlecased.
* A `header` module was added to `http`, contains header types.
* `SAFETY` is used as doc-string keyword for `unsafe` related comments.
* The `Uri` parser no longer recognizes Rocket route URIs.
2020-10-30 03:50:06 +00:00
|
|
|
pub use crate::state::State;
|
2016-10-03 10:39:56 +00:00
|
|
|
|
Introduce statically-enforced 'Rocket' phasing.
The core 'Rocket' type is parameterized: 'Rocket<P: Phase>', where
'Phase' is a newly introduced, sealed marker trait. The trait is
implemented by three new marker types representing the three launch
phases: 'Build', 'Ignite', and 'Orbit'. Progression through these three
phases, in order, is enforced, as are the invariants guaranteed by each
phase. In particular, an instance of 'Rocket' is guaranteed to be in its
final configuration after the 'Build' phase and represent a running
local or public server in the 'Orbit' phase. The 'Ignite' phase serves
as an intermediate, enabling inspection of a finalized but stationary
instance. Transition between phases validates the invariants required
by the transition.
All APIs have been adjusted appropriately, requiring either an instance
of 'Rocket' in a particular phase ('Rocket<Build>', 'Rocket<Ignite>', or
'Rocket<Orbit>') or operating generically on a 'Rocket<P>'.
Documentation is also updated and substantially improved to mention
required and guaranteed invariants.
Additionally, this commit makes the following relevant changes:
* 'Rocket::ignite()' is now a public interface.
* 'Rocket::{build,custom}' methods can no longer panic.
* 'Launch' fairings are now 'ignite' fairings.
* 'Liftoff' fairings are always run, even in local mode.
* All 'ignite' fairings run concurrently at ignition.
* Launch logging occurs on launch, not any point prior.
* Launch log messages have improved formatting.
* A new launch error kind, 'Config', was added.
* A 'fairing::Result' type alias was introduced.
* 'Shutdown::shutdown()' is now 'Shutdown::notify()'.
Some internal changes were also introduced:
* Fairing 'Info' name for 'Templates' is now 'Templating'.
* Shutdown is implemented using 'tokio::sync::Notify'.
* 'Client::debug()' is used nearly universally in tests.
Resolves #1154.
Resolves #1136.
2021-04-14 02:26:45 +00:00
|
|
|
/// Creates a [`Rocket`] instance with the default config provider: aliases
|
|
|
|
/// [`Rocket::build()`].
|
|
|
|
pub fn build() -> Rocket<Build> {
|
2021-04-08 08:07:52 +00:00
|
|
|
Rocket::build()
|
2016-10-03 10:39:56 +00:00
|
|
|
}
|
2016-11-04 13:35:04 +00:00
|
|
|
|
Introduce statically-enforced 'Rocket' phasing.
The core 'Rocket' type is parameterized: 'Rocket<P: Phase>', where
'Phase' is a newly introduced, sealed marker trait. The trait is
implemented by three new marker types representing the three launch
phases: 'Build', 'Ignite', and 'Orbit'. Progression through these three
phases, in order, is enforced, as are the invariants guaranteed by each
phase. In particular, an instance of 'Rocket' is guaranteed to be in its
final configuration after the 'Build' phase and represent a running
local or public server in the 'Orbit' phase. The 'Ignite' phase serves
as an intermediate, enabling inspection of a finalized but stationary
instance. Transition between phases validates the invariants required
by the transition.
All APIs have been adjusted appropriately, requiring either an instance
of 'Rocket' in a particular phase ('Rocket<Build>', 'Rocket<Ignite>', or
'Rocket<Orbit>') or operating generically on a 'Rocket<P>'.
Documentation is also updated and substantially improved to mention
required and guaranteed invariants.
Additionally, this commit makes the following relevant changes:
* 'Rocket::ignite()' is now a public interface.
* 'Rocket::{build,custom}' methods can no longer panic.
* 'Launch' fairings are now 'ignite' fairings.
* 'Liftoff' fairings are always run, even in local mode.
* All 'ignite' fairings run concurrently at ignition.
* Launch logging occurs on launch, not any point prior.
* Launch log messages have improved formatting.
* A new launch error kind, 'Config', was added.
* A 'fairing::Result' type alias was introduced.
* 'Shutdown::shutdown()' is now 'Shutdown::notify()'.
Some internal changes were also introduced:
* Fairing 'Info' name for 'Templates' is now 'Templating'.
* Shutdown is implemented using 'tokio::sync::Notify'.
* 'Client::debug()' is used nearly universally in tests.
Resolves #1154.
Resolves #1136.
2021-04-14 02:26:45 +00:00
|
|
|
/// Creates a [`Rocket`] instance with a custom config provider: aliases
|
|
|
|
/// [`Rocket::custom()`].
|
|
|
|
pub fn custom<T: figment::Provider>(provider: T) -> Rocket<Build> {
|
2020-09-03 05:41:31 +00:00
|
|
|
Rocket::custom(provider)
|
2016-11-04 13:35:04 +00:00
|
|
|
}
|
2019-08-14 16:30:59 +00:00
|
|
|
|
2021-04-28 08:41:13 +00:00
|
|
|
/// Retrofits support for `async fn` in trait impls and declarations.
|
|
|
|
///
|
2021-04-29 04:58:14 +00:00
|
|
|
/// Any trait declaration or trait `impl` decorated with `#[async_trait]` is
|
|
|
|
/// retrofitted with support for `async fn`s:
|
|
|
|
///
|
|
|
|
/// ```rust
|
|
|
|
/// # use rocket::*;
|
|
|
|
/// #[async_trait]
|
|
|
|
/// trait MyAsyncTrait {
|
|
|
|
/// async fn do_async_work();
|
|
|
|
/// }
|
|
|
|
///
|
|
|
|
/// #[async_trait]
|
|
|
|
/// impl MyAsyncTrait for () {
|
|
|
|
/// async fn do_async_work() { /* .. */ }
|
|
|
|
/// }
|
|
|
|
/// ```
|
|
|
|
///
|
|
|
|
/// All `impl`s for a trait declared with `#[async_trait]` must themselves be
|
|
|
|
/// decorated with `#[async_trait]`. Many of Rocket's traits, such as
|
|
|
|
/// [`FromRequest`](crate::request::FromRequest) and
|
|
|
|
/// [`Fairing`](crate::fairing::Fairing) are `async`. As such, implementations
|
|
|
|
/// of said traits must be decorated with `#[async_trait]`. See the individual
|
|
|
|
/// trait docs for trait-specific details.
|
|
|
|
///
|
|
|
|
/// For more details on `#[async_trait]`, see [`async_trait`](mod@async_trait).
|
2021-04-28 08:41:13 +00:00
|
|
|
#[doc(inline)]
|
|
|
|
pub use async_trait::async_trait;
|
|
|
|
|
2019-08-14 16:30:59 +00:00
|
|
|
/// WARNING: This is unstable! Do not use this method outside of Rocket!
|
|
|
|
#[doc(hidden)]
|
2021-04-28 09:01:35 +00:00
|
|
|
pub fn async_test<R>(fut: impl std::future::Future<Output = R>) -> R {
|
2020-12-24 01:02:40 +00:00
|
|
|
tokio::runtime::Builder::new_multi_thread()
|
2020-10-26 20:29:36 +00:00
|
|
|
.thread_name("rocket-test-worker-thread")
|
2020-12-24 01:02:40 +00:00
|
|
|
.worker_threads(1)
|
2019-12-11 00:34:23 +00:00
|
|
|
.enable_all()
|
|
|
|
.build()
|
|
|
|
.expect("create tokio runtime")
|
|
|
|
.block_on(fut)
|
2019-08-14 16:30:59 +00:00
|
|
|
}
|
2020-06-14 15:57:55 +00:00
|
|
|
|
|
|
|
/// WARNING: This is unstable! Do not use this method outside of Rocket!
|
|
|
|
#[doc(hidden)]
|
|
|
|
pub fn async_main<R>(fut: impl std::future::Future<Output = R> + Send) -> R {
|
2020-12-23 20:37:54 +00:00
|
|
|
// FIXME: The `workers` value won't reflect swaps of `Rocket` in attach
|
|
|
|
// fairings with different config values, or values from non-Rocket configs.
|
|
|
|
// See tokio-rs/tokio#3329 for a necessary solution in `tokio`.
|
2020-12-24 01:02:40 +00:00
|
|
|
tokio::runtime::Builder::new_multi_thread()
|
|
|
|
.worker_threads(Config::from(Config::figment()).workers)
|
2020-09-03 05:41:31 +00:00
|
|
|
.thread_name("rocket-worker-thread")
|
2020-06-14 15:57:55 +00:00
|
|
|
.enable_all()
|
|
|
|
.build()
|
|
|
|
.expect("create tokio runtime")
|
|
|
|
.block_on(fut)
|
|
|
|
}
|