From 869441dbf80ad359aba7bc67dd18b26dc1819c13 Mon Sep 17 00:00:00 2001 From: thanadolps Date: Sun, 25 Apr 2021 10:26:48 +0700 Subject: [PATCH] Change to catch up with latest rocket master - rocket::handler -> rocket::route - request.get_param() -> request.param - Change attach -> ignite and ignite -> build - Update lifetime signature of FromRequest --- examples/fairing.rs | 2 +- examples/guard.rs | 2 +- examples/manual.rs | 2 +- examples/mix.rs | 2 +- src/fairing.rs | 22 +++++++++++----------- src/headers.rs | 14 +++++++------- src/lib.rs | 18 +++++++++--------- tests/fairing.rs | 4 ++-- tests/guard.rs | 4 ++-- tests/headers.rs | 2 +- tests/manual.rs | 4 ++-- tests/mix.rs | 4 ++-- 12 files changed, 40 insertions(+), 40 deletions(-) diff --git a/examples/fairing.rs b/examples/fairing.rs index 9e33b4b..67b1b9a 100644 --- a/examples/fairing.rs +++ b/examples/fairing.rs @@ -23,7 +23,7 @@ async fn main() -> Result<(), Box> { } .to_cors()?; - rocket::ignite() + rocket::build() .mount("/", routes![cors]) .attach(cors) .launch() diff --git a/examples/guard.rs b/examples/guard.rs index 28f409a..924b86b 100644 --- a/examples/guard.rs +++ b/examples/guard.rs @@ -47,7 +47,7 @@ async fn main() -> Result<(), Box> { } .to_cors()?; - rocket::ignite() + rocket::build() .mount("/", routes![responder, response]) // Mount the routes to catch all the OPTIONS pre-flight requests .mount("/", rocket_cors::catch_all_options_routes()) diff --git a/examples/manual.rs b/examples/manual.rs index 9749664..c87f10b 100644 --- a/examples/manual.rs +++ b/examples/manual.rs @@ -71,7 +71,7 @@ fn cors_options() -> CorsOptions { #[rocket::main] async fn main() -> Result<(), Error> { - rocket::ignite() + rocket::build() .mount("/", routes![borrowed, response, owned, owned_options,]) .mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes .manage(cors_options().to_cors().expect("To not fail")) diff --git a/examples/mix.rs b/examples/mix.rs index 515bc94..8b2ce5b 100644 --- a/examples/mix.rs +++ b/examples/mix.rs @@ -56,7 +56,7 @@ fn cors_options_all() -> CorsOptions { #[rocket::main] async fn main() -> Result<(), Error> { - rocket::ignite() + rocket::build() .mount("/", routes![app, ping, ping_options,]) .mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes .manage(cors_options().to_cors().expect("To not fail")) diff --git a/src/fairing.rs b/src/fairing.rs index e3e2099..6b2f66c 100644 --- a/src/fairing.rs +++ b/src/fairing.rs @@ -19,14 +19,14 @@ enum CorsValidation { struct FairingErrorRoute {} #[rocket::async_trait] -impl rocket::handler::Handler for FairingErrorRoute { - async fn handle<'r, 's: 'r>( - &'s self, +impl rocket::route::Handler for FairingErrorRoute { + async fn handle<'r>( + &self, request: &'r Request<'_>, _: rocket::Data, - ) -> rocket::handler::Outcome<'r> { + ) -> rocket::route::Outcome<'r> { let status = request - .get_param::(0) + .param::(0) .unwrap_or(Ok(0)) .unwrap_or_else(|e| { error_!("Fairing Error Handling Route error: {:?}", e); @@ -102,13 +102,13 @@ impl rocket::fairing::Fairing for Cors { fn info(&self) -> rocket::fairing::Info { rocket::fairing::Info { name: "CORS", - kind: rocket::fairing::Kind::Attach + kind: rocket::fairing::Kind::Ignite | rocket::fairing::Kind::Request | rocket::fairing::Kind::Response, } } - async fn on_attach(&self, rocket: rocket::Rocket) -> Result { + async fn on_ignite(&self, rocket: rocket::Rocket) -> rocket::fairing::Result { Ok(rocket.mount( &self.fairing_route_base, vec![fairing_route(self.fairing_route_rank)], @@ -164,8 +164,8 @@ mod tests { .expect("Not to fail") } - fn rocket(fairing: Cors) -> Rocket { - Rocket::ignite().attach(fairing) + fn rocket(fairing: Cors) -> Rocket { + Rocket::build().attach(fairing) } #[test] @@ -187,8 +187,8 @@ mod tests { } #[rocket::async_test] - async fn error_route_is_mounted_on_attach() { - let rocket = rocket(make_cors_options()); + async fn error_route_is_mounted_on_ignite() { + let rocket = rocket(make_cors_options()).ignite().await.expect("to ignite"); let expected_uri = format!("{}/", CORS_ROOT); let error_route = rocket diff --git a/src/headers.rs b/src/headers.rs index c9a93bf..45ea97b 100644 --- a/src/headers.rs +++ b/src/headers.rs @@ -134,11 +134,11 @@ impl fmt::Display for Origin { } #[rocket::async_trait] -impl<'a, 'r> FromRequest<'a, 'r> for Origin { +impl<'r> FromRequest<'r> for Origin { type Error = crate::Error; async fn from_request( - request: &'a rocket::Request<'r>, + request: &'r rocket::Request<'_>, ) -> request::Outcome { Origin::from_request_sync(request) } @@ -180,11 +180,11 @@ impl FromStr for AccessControlRequestMethod { } #[rocket::async_trait] -impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestMethod { +impl<'r> FromRequest<'r> for AccessControlRequestMethod { type Error = crate::Error; async fn from_request( - request: &'a rocket::Request<'r>, + request: &'r rocket::Request<'_>, ) -> request::Outcome { AccessControlRequestMethod::from_request_sync(request) } @@ -238,11 +238,11 @@ impl FromStr for AccessControlRequestHeaders { } #[rocket::async_trait] -impl<'a, 'r> FromRequest<'a, 'r> for AccessControlRequestHeaders { +impl<'r> FromRequest<'r> for AccessControlRequestHeaders { type Error = crate::Error; async fn from_request( - request: &'a rocket::Request<'r>, + request: &'r rocket::Request<'_>, ) -> request::Outcome { AccessControlRequestHeaders::from_request_sync(request) } @@ -266,7 +266,7 @@ mod tests { /// Make a client with no routes for unit testing fn make_client() -> Client { - let rocket = rocket::ignite(); + let rocket = rocket::build(); Client::tracked(rocket).expect("valid rocket instance") } diff --git a/src/lib.rs b/src/lib.rs index 0cb89ff..2d74590 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1516,10 +1516,10 @@ impl<'r, 'o: 'r> Guard<'r> { } #[rocket::async_trait] -impl<'a, 'r> FromRequest<'a, 'r> for Guard<'r> { +impl<'r> FromRequest<'r> for Guard<'r> { type Error = Error; - async fn from_request(request: &'a Request<'r>) -> rocket::request::Outcome { + async fn from_request(request: &'r Request<'_>) -> rocket::request::Outcome { let options = match request.guard::>().await { Outcome::Success(options) => options, _ => { @@ -2009,15 +2009,15 @@ pub fn catch_all_options_routes() -> Vec { struct CatchAllOptionsRouteHandler {} #[rocket::async_trait] -impl rocket::handler::Handler for CatchAllOptionsRouteHandler { - async fn handle<'r, 's: 'r>( - &'s self, +impl rocket::route::Handler for CatchAllOptionsRouteHandler { + async fn handle<'r>( + &self, request: &'r Request<'_>, _: rocket::Data, - ) -> rocket::handler::Outcome<'r> { + ) -> rocket::route::Outcome<'r> { let guard: Guard<'_> = match request.guard().await { Outcome::Success(guard) => guard, - Outcome::Failure((status, _)) => return rocket::handler::Outcome::failure(status), + Outcome::Failure((status, _)) => return rocket::route::Outcome::failure(status), Outcome::Forward(()) => unreachable!("Should not be reachable"), }; @@ -2026,7 +2026,7 @@ impl rocket::handler::Handler for CatchAllOptionsRouteHandler { request ); - rocket::handler::Outcome::from(request, guard.responder(())) + rocket::route::Outcome::from(request, guard.responder(())) } } @@ -2080,7 +2080,7 @@ mod tests { /// Make a client with no routes for unit testing fn make_client() -> Client { - let rocket = rocket::ignite(); + let rocket = rocket::build(); Client::tracked(rocket).expect("valid rocket instance") } diff --git a/tests/fairing.rs b/tests/fairing.rs index e946042..d81347e 100644 --- a/tests/fairing.rs +++ b/tests/fairing.rs @@ -36,8 +36,8 @@ fn make_cors() -> Cors { .expect("To not fail") } -fn rocket() -> rocket::Rocket { - rocket::ignite() +fn rocket() -> rocket::Rocket { + rocket::build() .mount("/", routes![cors, panicking_route]) .attach(make_cors()) } diff --git a/tests/guard.rs b/tests/guard.rs index e1b15a9..876383d 100644 --- a/tests/guard.rs +++ b/tests/guard.rs @@ -78,8 +78,8 @@ fn make_cors() -> cors::Cors { .expect("To not fail") } -fn make_rocket() -> rocket::Rocket { - rocket::ignite() +fn make_rocket() -> rocket::Rocket { + rocket::build() .mount("/", routes![cors_responder, panicking_route]) .mount( "/", diff --git a/tests/headers.rs b/tests/headers.rs index 970bdfc..360cc12 100644 --- a/tests/headers.rs +++ b/tests/headers.rs @@ -32,7 +32,7 @@ fn request_headers( /// Tests that all the request headers are parsed correcly in a HTTP request #[test] fn request_headers_round_trip_smoke_test() { - let rocket = rocket::ignite().mount("/", routes![request_headers]); + let rocket = rocket::build().mount("/", routes![request_headers]); let client = Client::tracked(rocket).expect("A valid Rocket client"); let origin_header = Header::new(ORIGIN.as_str(), "https://foo.bar.xyz"); diff --git a/tests/manual.rs b/tests/manual.rs index e535ed3..3fa8f1e 100644 --- a/tests/manual.rs +++ b/tests/manual.rs @@ -95,8 +95,8 @@ fn make_different_cors_options() -> CorsOptions { } } -fn rocket() -> rocket::Rocket { - rocket::ignite() +fn rocket() -> rocket::Rocket { + rocket::build() .mount("/", routes![cors, panicking_route]) .mount("/", routes![owned, owned_options]) .mount("/", catch_all_options_routes()) // mount the catch all routes diff --git a/tests/mix.rs b/tests/mix.rs index b684ef7..55da7b6 100644 --- a/tests/mix.rs +++ b/tests/mix.rs @@ -61,8 +61,8 @@ fn cors_options_all() -> CorsOptions { Default::default() } -fn rocket() -> rocket::Rocket { - rocket::ignite() +fn rocket() -> rocket::Rocket { + rocket::build() .mount("/", routes![app, ping, ping_options,]) .mount("/", rocket_cors::catch_all_options_routes()) // mount the catch all routes .manage(cors_options().to_cors().expect("Not to fail"))