Skip to content

Commit

Permalink
Revamp configuration.
Browse files Browse the repository at this point in the history
This commit completely overhauls Rocket's configuration systems, basing
it on the new Figment library. It includes many breaking changes
pertaining to configuration. They are:

  * "Environments" are replaced by "profiles".
  * 'ROCKET_PROFILE' takes the place of 'ROCKET_ENV'.
  * Profile names are now arbitrary, but 'debug' and 'release' are given
    special treatment as default profiles for the debug and release
    compilation profiles.
  * A 'default' profile now sits along-side the meta 'global' profile.
  * The concept of "extras" is no longer present; users can extract any
    values they want from the configured 'Figment'.
  * The 'Poolable' trait takes an '&Config'.
  * The 'secrets' feature is disabled by default.
  * It is a hard error if 'secrets' is enabled under the 'release'
    profile and no 'secret_key' is configured.
  * 'ConfigBuilder' no longer exists: all fields of 'Config' are public
    with public constructors for each type.
  * 'keep_alive' is disabled with '0', not 'false' or 'off'.
  * Inlined error variants into the 'Error' structure.
  * 'LoggingLevel' is now 'LogLevel'.
  * Limits can now be specified in SI units: "1 MiB".

The summary of other changes are:

  * The default config file can be configured with 'ROCKET_CONFIG'.
  * HTTP/1 and HTTP/2 keep-alive configuration is restored.
  * 'ctrlc' is now a recognized config option.
  * 'serde' is now a core dependency.
  * TLS misconfiguration errors are improved.
  * Several example use '_' as the return type of '#[launch]' fns.
  * 'AdHoc::config()' was added for simple config extraction.
  * Added more documentation for using 'Limits'.
  * Launch information is no longer treated specially.
  * The configuration guide was rewritten.

Resolves #852.
Resolves #209.
Closes #1404.
Closes #652.
  • Loading branch information
SergioBenitez committed Oct 21, 2020
1 parent 8da034a commit 1fb0614
Show file tree
Hide file tree
Showing 61 changed files with 1,997 additions and 4,364 deletions.
8 changes: 4 additions & 4 deletions contrib/codegen/src/database.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,13 @@ pub fn database_attr(attr: TokenStream, input: TokenStream) -> Result<TokenStrea
let databases = quote_spanned!(span => ::rocket_contrib::databases);
let request = quote!(::rocket::request);

let generated_types = quote_spanned! { span =>
let request_guard_type = quote_spanned! { span =>
/// The request guard type.
#vis struct #guard_type(#databases::Connection<Self, #conn_type>);
};

Ok(quote! {
#generated_types
#request_guard_type

impl #guard_type {
/// Returns a fairing that initializes the associated database
Expand Down Expand Up @@ -110,8 +110,8 @@ pub fn database_attr(attr: TokenStream, input: TokenStream) -> Result<TokenStrea
impl<'a, 'r> #request::FromRequest<'a, 'r> for #guard_type {
type Error = ();

async fn from_request(request: &'a #request::Request<'r>) -> #request::Outcome<Self, ()> {
<#databases::Connection<Self, #conn_type>>::from_request(request).await.map(Self)
async fn from_request(req: &'a #request::Request<'r>) -> #request::Outcome<Self, ()> {
<#databases::Connection<Self, #conn_type>>::from_request(req).await.map(Self)
}
}
}.into())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unexpected end of input, expected literal
error: unexpected end of input, expected string literal
--> $DIR/database-syntax.rs:6:1
|
6 | #[database]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: unexpected end of input, expected literal
error: unexpected end of input, expected string literal
--> $DIR/database-syntax.rs:6:1
|
6 | #[database]
Expand Down
5 changes: 4 additions & 1 deletion contrib/lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ edition = "2018"
[features]
# Internal use only.
templates = ["serde", "serde_json", "glob", "notify"]
databases = ["r2d2", "tokio/blocking", "tokio/rt-threaded", "rocket_contrib_codegen/database_attribute"]
databases = [
"serde", "r2d2", "tokio/blocking", "tokio/rt-threaded",
"rocket_contrib_codegen/database_attribute"
]

# User-facing features.
default = ["json", "serve"]
Expand Down
Loading

0 comments on commit 1fb0614

Please sign in to comment.