Rename 'Rocket::configure()' to 'reconfigure()'.

This commit is contained in:
Sergio Benitez 2024-04-25 13:21:59 -07:00
parent b34085392d
commit 836e64fec3
10 changed files with 47 additions and 43 deletions

View File

@ -30,7 +30,7 @@ use crate::{Request, Response};
/// #[launch]
/// fn rocket() -> _ {
/// rocket::build().mount("/", routes![hello_world])
/// # .configure(rocket::Config::debug_default())
/// # .reconfigure(rocket::Config::debug_default())
/// }
///
/// # async fn read_body_manually() -> io::Result<()> {

View File

@ -27,7 +27,7 @@ use super::Client;
/// #[launch]
/// fn rocket() -> _ {
/// rocket::build().mount("/", routes![hello_world])
/// # .configure(rocket::Config::debug_default())
/// # .reconfigure(rocket::Config::debug_default())
/// }
///
/// # fn read_body_manually() -> io::Result<()> {

View File

@ -141,7 +141,7 @@ macro_rules! pub_client_impl {
.merge((config::Config::LOG_LEVEL, config::LogLevel::Debug))
.select(config::Config::DEBUG_PROFILE);
Self::tracked(rocket.configure(figment)) $(.$suffix)?
Self::tracked(rocket.reconfigure(figment)) $(.$suffix)?
}
/// Returns a reference to the `Rocket` this client is creating requests

View File

@ -197,13 +197,11 @@ impl Rocket<Build> {
rocket.attach(Shield::default())
}
/// Sets the configuration provider in `self` to `provider`.
/// Overrides the current configuration provider with `provider`.
///
/// A [`Figment`] generated from the current `provider` can _always_ be
/// retrieved via [`Rocket::figment()`]. However, because the provider can
/// be changed at any point prior to ignition, a [`Config`] can only be
/// retrieved in the ignite or orbit phases, or by manually extracting one
/// from a particular figment.
/// The default provider, or a provider previously set with
/// [`Rocket::custom()`] or [`Rocket::reconfigure()`], is overriden by
/// `provider`.
///
/// # Example
///
@ -229,7 +227,7 @@ impl Rocket<Build> {
/// .merge((Config::IDENT, "Example"));
///
/// let rocket = rocket::custom(&config)
/// .configure(figment)
/// .reconfigure(figment)
/// .ignite().await?;
///
/// assert_eq!(rocket.config().ident.as_str(), Some("Example"));
@ -238,7 +236,7 @@ impl Rocket<Build> {
/// # });
/// ```
#[must_use]
pub fn configure<T: Provider>(mut self, provider: T) -> Self {
pub fn reconfigure<T: Provider>(mut self, provider: T) -> Self {
self.figment = Figment::from(provider);
self
}
@ -522,7 +520,7 @@ impl Rocket<Build> {
/// #[rocket::main]
/// async fn main() -> Result<(), rocket::Error> {
/// let rocket = rocket::build()
/// # .configure(rocket::Config::debug_default())
/// # .reconfigure(rocket::Config::debug_default())
/// .attach(AdHoc::on_ignite("Manage State", |rocket| async move {
/// rocket.manage(String::from("managed string"))
/// }));
@ -918,6 +916,12 @@ impl<P: Phase> Rocket<P> {
/// `self`. To extract a typed config, prefer to use
/// [`AdHoc::config()`](crate::fairing::AdHoc::config()).
///
/// Note; A [`Figment`] generated from the current `provider` can _always_
/// be retrieved via this method. However, because the provider can be
/// changed at any point prior to ignition, a [`Config`] can only be
/// retrieved in the ignite or orbit phases, or by manually extracting one
/// from a particular figment.
///
/// # Example
///
/// ```rust

View File

@ -41,7 +41,7 @@ use crate::{Rocket, Ignite};
///
/// # use rocket::{Config, error::ErrorKind};
/// # rocket::async_test(async {
/// # let result = rocket().configure(Config::debug_default()).ignite().await;
/// # let result = rocket().reconfigure(Config::debug_default()).ignite().await;
/// # assert!(matches!(result.unwrap_err().kind(), ErrorKind::SentinelAborts(..)));
/// # })
/// ```
@ -76,7 +76,7 @@ use crate::{Rocket, Ignite};
///
/// # use rocket::{Config, error::ErrorKind};
/// # rocket::async_test(async {
/// # rocket().configure(Config::debug_default()).ignite().await.unwrap();
/// # rocket().reconfigure(Config::debug_default()).ignite().await.unwrap();
/// # })
/// ```
///

View File

@ -9,7 +9,7 @@ fn one_state<'r>(_three: &'r State<u8>, s: &'r str) -> &'r str { s }
#[async_test]
async fn state_sentinel_works() {
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![two_states])
.ignite().await
.unwrap_err();
@ -17,7 +17,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 2));
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![two_states])
.manage(String::new())
.ignite().await
@ -26,7 +26,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 1));
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![two_states])
.manage(1 as u32)
.ignite().await
@ -35,7 +35,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 1));
let result = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![two_states])
.manage(String::new())
.manage(1 as u32)
@ -44,7 +44,7 @@ async fn state_sentinel_works() {
assert!(result.is_ok());
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![one_state])
.ignite().await
.unwrap_err();
@ -52,7 +52,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 1));
let result = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![one_state])
.manage(1 as u8)
.ignite().await;
@ -60,7 +60,7 @@ async fn state_sentinel_works() {
assert!(result.is_ok());
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![one_state, two_states])
.ignite().await
.unwrap_err();
@ -68,7 +68,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 3));
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![one_state, two_states])
.manage(1 as u32)
.ignite().await
@ -77,7 +77,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 2));
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![one_state, two_states])
.manage(1 as u8)
.ignite().await
@ -86,7 +86,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 2));
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![one_state, two_states])
.manage(1 as u32)
.manage(1 as u8)
@ -96,7 +96,7 @@ async fn state_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 1));
let result = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![one_state, two_states])
.manage(1 as u32)
.manage(1 as u8)
@ -128,7 +128,7 @@ fn with_data(_data: Data) {}
#[async_test]
async fn data_sentinel_works() {
let err = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![with_data])
.ignite().await
.unwrap_err();
@ -136,7 +136,7 @@ async fn data_sentinel_works() {
assert!(matches!(err.kind(), SentinelAborts(vec) if vec.len() == 1));
let result = rocket::build()
.configure(Config::debug_default())
.reconfigure(Config::debug_default())
.mount("/", routes![with_data])
.manage(Data)
.ignite().await;

View File

@ -101,7 +101,7 @@ async fn async_slow_shutdown_doesnt_elongate_grace() {
let rocket = rocket::build()
.manage(Flags::default())
.configure(config)
.reconfigure(config)
.attach(AdHoc::on_shutdown("Slow Shutdown", |rocket| Box::pin(async move {
tokio::time::sleep(std::time::Duration::from_secs(4)).await;
let flags = rocket.state::<Flags>().unwrap();
@ -141,7 +141,7 @@ fn background_tasks_dont_prevent_terminate() {
config.shutdown.grace = 1;
config.shutdown.mercy = 1;
let rocket = rocket::build().configure(config).mount("/", routes![index]);
let rocket = rocket::build().reconfigure(config).mount("/", routes![index]);
let client = Client::debug(rocket).unwrap();
let response = client.get("/").dispatch();

View File

@ -180,7 +180,7 @@ testing: we _want_ our tests to panic when something goes wrong.
```rust
# #[rocket::launch]
# fn rocket() -> _ {
# rocket::build().configure(rocket::Config::debug_default())
# rocket::build().reconfigure(rocket::Config::debug_default())
# }
# use rocket::local::blocking::Client;
@ -194,7 +194,7 @@ application's response:
# use rocket::uri;
# #[rocket::launch]
# fn rocket() -> _ {
# rocket::build().configure(rocket::Config::debug_default())
# rocket::build().reconfigure(rocket::Config::debug_default())
# }
# #[rocket::get("/")]

View File

@ -75,7 +75,7 @@ fn validate_profiles(profiles: &[&str]) {
};
let figment = Config::figment().merge(config).select(profile);
let client = Client::tracked_secure(super::rocket().configure(figment)).unwrap();
let client = Client::tracked_secure(super::rocket().reconfigure(figment)).unwrap();
let response = client.get("/").dispatch();
assert_eq!(response.into_string().unwrap(), "Hello, world!");

View File

@ -34,28 +34,28 @@ static TLS_CONFIG: &str = r#"
trait RocketExt {
fn default() -> Self;
fn tls_default() -> Self;
fn configure_with_toml(self, toml: &str) -> Self;
fn reconfigure_with_toml(self, toml: &str) -> Self;
}
impl RocketExt for Rocket<Build> {
fn default() -> Self {
rocket::build().configure_with_toml(DEFAULT_CONFIG)
rocket::build().reconfigure_with_toml(DEFAULT_CONFIG)
}
fn tls_default() -> Self {
rocket::build()
.configure_with_toml(DEFAULT_CONFIG)
.configure_with_toml(TLS_CONFIG)
.reconfigure_with_toml(DEFAULT_CONFIG)
.reconfigure_with_toml(TLS_CONFIG)
}
fn configure_with_toml(self, toml: &str) -> Self {
fn reconfigure_with_toml(self, toml: &str) -> Self {
use rocket::figment::{Figment, providers::{Format, Toml}};
let toml = toml.replace("{ROCKET}", rocket::fs::relative!("../"));
let config = Figment::from(self.figment())
.merge(Toml::string(&toml).nested());
self.configure(config)
self.reconfigure(config)
}
}
@ -139,7 +139,7 @@ fn tls_info() -> Result<()> {
let server = Server::spawn((), |(token, _)| {
let rocket = rocket::build()
.configure_with_toml(TLS_CONFIG)
.reconfigure_with_toml(TLS_CONFIG)
.mount("/", routes![hello_world]);
token.with_launch(rocket, |rocket| {
@ -229,7 +229,7 @@ fn test_mtls(mandatory: bool) -> Result<()> {
}
Rocket::tls_default()
.configure_with_toml(&mtls_config)
.reconfigure_with_toml(&mtls_config)
.mount("/", routes![hello, hi])
})?;
@ -318,7 +318,7 @@ fn sni_resolver() -> Result<()> {
#[get("/")] fn index() { }
Rocket::default()
.configure_with_toml(SNI_TLS_CONFIG)
.reconfigure_with_toml(SNI_TLS_CONFIG)
.mount("/", routes![index])
.attach(SniResolver::fairing())
}?;
@ -348,7 +348,7 @@ fn sni_resolver() -> Result<()> {
fn tcp_unix_listener_fail() -> Result<()> {
let server = spawn! {
Rocket::default().configure_with_toml("[default]\naddress = 123")
Rocket::default().reconfigure_with_toml("[default]\naddress = 123")
};
if let Err(Error::Liftoff(stdout, _)) = server {
@ -359,7 +359,7 @@ fn tcp_unix_listener_fail() -> Result<()> {
}
let server = Server::spawn((), |(token, _)| {
let rocket = Rocket::default().configure_with_toml("[default]\naddress = \"unix:foo\"");
let rocket = Rocket::default().reconfigure_with_toml("[default]\naddress = \"unix:foo\"");
token.launch_with::<TcpListener>(rocket)
});