From d89c7024edc5f64294ba7386b08215c93886fac7 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Sat, 27 Jun 2020 22:59:40 -0700 Subject: [PATCH] Replace 'Manifest' with 'Cargo'. This is largely an internal change. Prior to this commit, the 'Manifest' type, now replaced with the 'Cargo' type, robbed responsibility from the core 'Rocket' type. This new construction restores the previous responsibility and makes it clear that 'Cargo' is _only_ for freezing, and representing the stability of, Rocket's internal state. --- contrib/codegen/src/database.rs | 4 +- contrib/lib/src/databases.rs | 2 +- contrib/lib/src/helmet/helmet.rs | 8 +- contrib/lib/src/templates/mod.rs | 8 +- contrib/lib/tests/templates.rs | 14 +- core/codegen/src/attribute/async_entry.rs | 1 + core/lib/benches/simple-routing.rs | 2 +- core/lib/src/catcher.rs | 9 + core/lib/src/ext.rs | 52 +- core/lib/src/fairing/ad_hoc.rs | 10 +- core/lib/src/fairing/fairings.rs | 6 +- core/lib/src/fairing/info_kind.rs | 1 + core/lib/src/fairing/mod.rs | 14 +- core/lib/src/lib.rs | 2 +- core/lib/src/local/client.rs | 41 +- core/lib/src/local/request.rs | 6 +- core/lib/src/request/request.rs | 14 +- core/lib/src/request/state.rs | 12 +- core/lib/src/request/tests.rs | 2 +- core/lib/src/rocket.rs | 649 +++++++++++---------- core/lib/src/router/collider.rs | 4 +- core/lib/src/router/mod.rs | 4 +- core/lib/tests/attach-inspect.rs | 43 ++ examples/cookies/src/tests.rs | 4 +- examples/handlebars_templates/src/tests.rs | 6 +- examples/request_local_state/src/tests.rs | 6 +- examples/state/src/tests.rs | 8 +- examples/tera_templates/src/tests.rs | 6 +- 28 files changed, 534 insertions(+), 404 deletions(-) create mode 100644 core/lib/tests/attach-inspect.rs diff --git a/contrib/codegen/src/database.rs b/contrib/codegen/src/database.rs index efd23441..2fea4263 100644 --- a/contrib/codegen/src/database.rs +++ b/contrib/codegen/src/database.rs @@ -118,8 +118,8 @@ pub fn database_attr(attr: TokenStream, input: TokenStream) -> Result Option { - manifest.state::<#pool_type>() + pub fn get_one(cargo: &::rocket::Cargo) -> Option { + cargo.state::<#pool_type>() .and_then(|pool| pool.0.get().ok()) .map(#guard_type) } diff --git a/contrib/lib/src/databases.rs b/contrib/lib/src/databases.rs index 2251a8ec..37a8a254 100644 --- a/contrib/lib/src/databases.rs +++ b/contrib/lib/src/databases.rs @@ -239,7 +239,7 @@ //! Returns a fairing that initializes the associated database connection //! pool. //! -//! * `fn get_one(&Manifest) -> Option` +//! * `fn get_one(&Cargo) -> Option` //! //! Retrieves a connection from the configured pool. Returns `Some` as long //! as `Self::fairing()` has been attached and there is at least one diff --git a/contrib/lib/src/helmet/helmet.rs b/contrib/lib/src/helmet/helmet.rs index e6a863eb..8ca38316 100644 --- a/contrib/lib/src/helmet/helmet.rs +++ b/contrib/lib/src/helmet/helmet.rs @@ -3,7 +3,7 @@ use std::sync::atomic::{AtomicBool, Ordering}; use rocket::http::uncased::UncasedStr; use rocket::fairing::{Fairing, Info, Kind}; -use rocket::{Manifest, Request, Response}; +use rocket::{Cargo, Request, Response}; use crate::helmet::*; @@ -201,9 +201,9 @@ impl Fairing for SpaceHelmet { self.apply(res); } - fn on_launch(&self, manifest: &Manifest) { - if manifest.config().tls_enabled() - && !manifest.config().environment.is_dev() + fn on_launch(&self, cargo: &Cargo) { + if cargo.config().tls_enabled() + && !cargo.config().environment.is_dev() && !self.is_enabled::() { warn_!("Space Helmet: deploying with TLS without enabling HSTS."); diff --git a/contrib/lib/src/templates/mod.rs b/contrib/lib/src/templates/mod.rs index 4cd2c8c8..ada0b48c 100644 --- a/contrib/lib/src/templates/mod.rs +++ b/contrib/lib/src/templates/mod.rs @@ -141,7 +141,7 @@ use serde_json::{Value, to_value}; use std::borrow::Cow; use std::path::PathBuf; -use rocket::Manifest; +use rocket::Cargo; use rocket::request::Request; use rocket::fairing::Fairing; use rocket::response::{self, Content, Responder}; @@ -340,15 +340,15 @@ impl Template { /// /// # context.insert("test", "test"); /// # #[allow(unused_variables)] - /// let template = Template::show(client.manifest(), "index", context); + /// let template = Template::show(client.cargo(), "index", context); /// # }); /// } /// ``` #[inline] - pub fn show(manifest: &Manifest, name: S, context: C) -> Option + pub fn show(cargo: &Cargo, name: S, context: C) -> Option where S: Into>, C: Serialize { - let ctxt = manifest.state::().map(ContextManager::context).or_else(|| { + let ctxt = cargo.state::().map(ContextManager::context).or_else(|| { warn!("Uninitialized template context: missing fairing."); info!("To use templates, you must attach `Template::fairing()`."); info!("See the `Template` documentation for more information."); diff --git a/contrib/lib/tests/templates.rs b/contrib/lib/tests/templates.rs index 6d7e0361..ed51bfed 100644 --- a/contrib/lib/tests/templates.rs +++ b/contrib/lib/tests/templates.rs @@ -52,17 +52,17 @@ mod templates_tests { #[rocket::async_test] async fn test_tera_templates() { let mut rocket = rocket(); - let manifest = rocket.inspect().await; + let cargo = rocket.inspect().await; let mut map = HashMap::new(); map.insert("title", "_test_"); map.insert("content", "