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))]
|
2017-06-11 08:03:59 +00:00
|
|
|
|
2019-06-13 01:48:02 +00:00
|
|
|
#![warn(rust_2018_idioms)]
|
|
|
|
|
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
|
|
|
//!
|
2018-10-07 04:16:02 +00:00
|
|
|
//! You may also be interested in looking at the
|
|
|
|
//! [`rocket_contrib`](../rocket_contrib) documentation, which contains
|
|
|
|
//! automatic JSON (de)serialiazation, templating support, static file serving,
|
|
|
|
//! and other useful features.
|
2018-10-06 13:25:17 +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
|
|
|
//!
|
|
|
|
//! ## Libraries
|
|
|
|
//!
|
2018-10-05 04:44:42 +00:00
|
|
|
//! Rocket's functionality is split into two crates:
|
2016-10-03 00:52:04 +00:00
|
|
|
//!
|
2018-10-06 13:25:17 +00:00
|
|
|
//! 1. Core - This core library. Needed by every Rocket application.
|
2018-10-07 04:16:02 +00:00
|
|
|
//! 2. [Contrib](../rocket_contrib) - Provides useful functionality for many
|
2017-02-03 09:15:01 +00:00
|
|
|
//! Rocket applications. Completely optional.
|
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
|
|
|
//! ```
|
|
|
|
//!
|
2020-10-21 11:54:24 +00:00
|
|
|
//! See the [guide](https://rocket.rs/master/guide) for more information on how to
|
2016-10-18 02:29:58 +00:00
|
|
|
//! write Rocket applications. Here's a simple example to get you started:
|
|
|
|
//!
|
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() -> _ {
|
2020-06-16 12:01:26 +00:00
|
|
|
//! rocket::ignite().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
|
|
|
|
//!
|
2020-09-03 05:41:31 +00:00
|
|
|
//! There are two optional, disabled-by-default features:
|
|
|
|
//!
|
|
|
|
//! * **secrets:** Enables support for [private cookies].
|
|
|
|
//! * **tls:** Enables support for [TLS].
|
|
|
|
//!
|
2020-10-22 10:27:04 +00:00
|
|
|
//! The features can be enabled in `Rocket.toml`:
|
2020-07-22 19:21:19 +00:00
|
|
|
//!
|
|
|
|
//! ```toml
|
|
|
|
//! [dependencies]
|
2020-09-03 05:41:31 +00:00
|
|
|
//! rocket = { version = "0.5.0-dev", features = ["secrets", "tls"] }
|
2020-07-22 19:21:19 +00:00
|
|
|
//! ```
|
|
|
|
//!
|
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
|
|
|
|
//!
|
2017-02-03 09:15:01 +00:00
|
|
|
//! Rocket and Rocket libraries are configured via the `Rocket.toml` file and/or
|
|
|
|
//! `ROCKET_{PARAM}` environment variables. For more information on how to
|
2018-10-06 13:25:17 +00:00
|
|
|
//! configure Rocket, see the [configuration section] of the guide as well as
|
|
|
|
//! the [`config`] module documentation.
|
|
|
|
//!
|
2020-10-21 11:54:24 +00:00
|
|
|
//! [configuration section]: https://rocket.rs/master/guide/configuration/
|
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
|
|
|
|
//! documentation and the [testing chapter of the guide] include detailed
|
|
|
|
//! examples.
|
|
|
|
//!
|
2020-10-21 11:54:24 +00:00
|
|
|
//! [testing chapter of the guide]: https://rocket.rs/master/guide/testing/#testing
|
2016-10-04 00:09:13 +00:00
|
|
|
|
2018-10-22 06:53:09 +00:00
|
|
|
#[allow(unused_imports)] #[macro_use] extern crate rocket_codegen;
|
2020-02-26 00:56:59 +00:00
|
|
|
pub use rocket_codegen::*;
|
2020-01-31 04:47:57 +00:00
|
|
|
pub use async_trait::*;
|
2018-04-12 23:07:37 +00:00
|
|
|
|
2016-10-04 00:09:13 +00:00
|
|
|
#[macro_use] extern crate log;
|
2016-10-04 10:54:24 +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.
|
2020-07-24 02:59:09 +00:00
|
|
|
#[doc(hidden)]
|
|
|
|
pub use yansi;
|
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
|
|
|
|
2016-09-30 22:20:11 +00:00
|
|
|
#[doc(hidden)] #[macro_use] pub mod logger;
|
2019-09-11 01:04:34 +00:00
|
|
|
#[macro_use] pub mod outcome;
|
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;
|
2016-10-25 11:24:07 +00:00
|
|
|
pub mod data;
|
2016-12-15 08:47:31 +00:00
|
|
|
pub mod handler;
|
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;
|
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::*;
|
|
|
|
}
|
|
|
|
|
2020-07-22 23:10:02 +00:00
|
|
|
mod shutdown;
|
2016-04-01 23:54:53 +00:00
|
|
|
mod router;
|
|
|
|
mod rocket;
|
2020-10-23 00:37:05 +00:00
|
|
|
mod server;
|
2016-04-03 10:36:30 +00:00
|
|
|
mod codegen;
|
2018-10-23 20:22:26 +00:00
|
|
|
mod ext;
|
2016-04-02 07:51:40 +00:00
|
|
|
|
2020-09-03 05:41:31 +00:00
|
|
|
#[doc(hidden)] pub use log::{info, warn, error, debug};
|
2019-06-13 01:48:02 +00:00
|
|
|
#[doc(inline)] pub use crate::response::Response;
|
2020-07-30 06:07:22 +00:00
|
|
|
#[doc(hidden)] pub use crate::codegen::{StaticRouteInfo, StaticCatcherInfo};
|
2019-06-13 01:48:02 +00:00
|
|
|
#[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;
|
2019-06-13 01:48:02 +00:00
|
|
|
pub use crate::router::Route;
|
|
|
|
pub use crate::request::{Request, State};
|
2020-10-22 10:27:04 +00:00
|
|
|
pub use crate::rocket::Rocket;
|
2020-07-22 23:10:02 +00:00
|
|
|
pub use crate::shutdown::Shutdown;
|
2016-10-03 10:39:56 +00:00
|
|
|
|
2018-10-06 13:25:17 +00:00
|
|
|
/// Alias to [`Rocket::ignite()`] Creates a new instance of `Rocket`.
|
2016-10-03 10:39:56 +00:00
|
|
|
pub fn ignite() -> Rocket {
|
|
|
|
Rocket::ignite()
|
|
|
|
}
|
2016-11-04 13:35:04 +00:00
|
|
|
|
2018-10-06 13:25:17 +00:00
|
|
|
/// Alias to [`Rocket::custom()`]. Creates a new instance of `Rocket` with a
|
2020-09-03 05:41:31 +00:00
|
|
|
/// custom configuration provider.
|
|
|
|
pub fn custom<T: figment::Provider>(provider: T) -> Rocket {
|
|
|
|
Rocket::custom(provider)
|
2016-11-04 13:35:04 +00:00
|
|
|
}
|
2019-08-14 16:30:59 +00:00
|
|
|
|
|
|
|
/// WARNING: This is unstable! Do not use this method outside of Rocket!
|
|
|
|
#[doc(hidden)]
|
2019-08-24 17:27:10 +00:00
|
|
|
pub fn async_test<R>(fut: impl std::future::Future<Output = R> + Send) -> R {
|
2019-12-11 00:34:23 +00:00
|
|
|
tokio::runtime::Builder::new()
|
2020-10-26 20:29:36 +00:00
|
|
|
.threaded_scheduler()
|
|
|
|
.thread_name("rocket-test-worker-thread")
|
|
|
|
.core_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-06-14 15:57:55 +00:00
|
|
|
tokio::runtime::Builder::new()
|
|
|
|
.threaded_scheduler()
|
2020-12-23 20:37:54 +00:00
|
|
|
.core_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)
|
|
|
|
}
|