Skip to content

Commit 04ae827

Browse files
committed
Fix formatting issues
1 parent 6d06ac7 commit 04ae827

File tree

14 files changed

+65
-29
lines changed

14 files changed

+65
-29
lines changed

core/http/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ memchr = "2"
3636
stable-pattern = "0.1"
3737
cookie = { version = "0.18", features = ["percent-encode"] }
3838
state = "0.6"
39-
transient = { version = "0.4", path = "/home/matthew/transient" }
39+
transient = { version = "0.4", path = "/code/matthew/transient" }
4040

4141
[dependencies.serde]
4242
version = "1.0"

core/lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ tokio-stream = { version = "0.1.6", features = ["signal", "time"] }
7474
cookie = { version = "0.18", features = ["percent-encode"] }
7575
futures = { version = "0.3.30", default-features = false, features = ["std"] }
7676
state = "0.6"
77-
transient = { version = "0.4", features = ["either"], path = "/home/matthew/transient" }
77+
transient = { version = "0.4", features = ["either"], path = "/code/matthew/transient" }
7878

7979
# tracing
8080
tracing = { version = "0.1.40", default-features = false, features = ["std", "attributes"] }

core/lib/src/catcher/catcher.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,9 @@ impl Catcher {
322322

323323
impl Default for Catcher {
324324
fn default() -> Self {
325-
fn handler<'r>(s: Status, req: &'r Request<'_>, _e: Option<&(dyn TypedError<'r> + 'r)>) -> BoxFuture<'r> {
325+
fn handler<'r>(s: Status, req: &'r Request<'_>, _e: Option<&'r dyn TypedError<'r>>)
326+
-> BoxFuture<'r>
327+
{
326328
Box::pin(async move { Ok(default_handler(s, req)) })
327329
}
328330

@@ -342,7 +344,8 @@ pub struct StaticInfo {
342344
/// The catcher's error type.
343345
pub error_type: Option<(TypeId, &'static str)>,
344346
/// The catcher's handler, i.e, the annotated function.
345-
pub handler: for<'r> fn(Status, &'r Request<'_>, Option<&'r (dyn TypedError<'r> + 'r)>) -> BoxFuture<'r>,
347+
pub handler: for<'r> fn(Status, &'r Request<'_>, Option<&'r dyn TypedError<'r>>)
348+
-> BoxFuture<'r>,
346349
/// The file, line, and column where the catcher was defined.
347350
pub location: (&'static str, u32, u32),
348351
}

core/lib/src/catcher/handler.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,17 @@ pub trait Handler: Cloneable + Send + Sync + 'static {
100100
/// Nevertheless, failure is allowed, both for convenience and necessity. If
101101
/// an error handler fails, Rocket's default `500` catcher is invoked. If it
102102
/// succeeds, the returned `Response` is used to respond to the client.
103-
async fn handle<'r>(&self, status: Status, req: &'r Request<'_>, error: Option<&'r (dyn TypedError<'r> + 'r)>)
104-
-> Result<'r>;
103+
async fn handle<'r>(
104+
&self,
105+
status: Status,
106+
req: &'r Request<'_>,
107+
error: Option<&'r dyn TypedError<'r>>
108+
) -> Result<'r>;
105109
}
106110

107111
// We write this manually to avoid double-boxing.
108112
impl<F: Clone + Sync + Send + 'static> Handler for F
109-
where for<'x> F: Fn(Status, &'x Request<'_>, Option<&'x (dyn TypedError<'x> + 'x)>) -> BoxFuture<'x>,
113+
where for<'x> F: Fn(Status, &'x Request<'_>, Option<&'x dyn TypedError<'x>>) -> BoxFuture<'x>,
110114
{
111115
fn handle<'r, 'life0, 'life1, 'life2, 'async_trait>(
112116
&'life0 self,
@@ -125,7 +129,9 @@ impl<F: Clone + Sync + Send + 'static> Handler for F
125129

126130
// Used in tests! Do not use, please.
127131
#[doc(hidden)]
128-
pub fn dummy_handler<'r>(_: Status, _: &'r Request<'_>, _: Option<&(dyn TypedError<'r> + 'r)>) -> BoxFuture<'r> {
132+
pub fn dummy_handler<'r>(_: Status, _: &'r Request<'_>, _: Option<&'r dyn TypedError<'r>>)
133+
-> BoxFuture<'r>
134+
{
129135
Box::pin(async move { Ok(Response::new()) })
130136
}
131137

core/lib/src/catcher/types.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub trait TypedError<'r>: AsAny<Inv<'r>> + Send + Sync + 'r {
4040
fn respond_to(&self, request: &'r Request<'_>) -> Result<Response<'r>, Status> {
4141
Err(Status::InternalServerError)
4242
}
43-
43+
4444
/// A descriptive name of this error type. Defaults to the type name.
4545
fn name(&self) -> &'static str { std::any::type_name::<Self>() }
4646

@@ -92,7 +92,7 @@ impl<'r, L, R> TypedError<'r> for Either<L, R>
9292

9393
fn name(&self) -> &'static str { std::any::type_name::<Self>() }
9494

95-
fn source(&'r self) -> Option<&'r (dyn TypedError<'r> + 'r)> {
95+
fn source(&'r self) -> Option<&'r (dyn TypedError<'r> + 'r)> {
9696
match self {
9797
Self::Left(v) => Some(v),
9898
Self::Right(v) => Some(v),

core/lib/src/erased.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,10 @@ impl ErasedRequest {
121121
let parent: &'static ErasedRequest = unsafe { transmute(parent) };
122122
let rocket: &Rocket<Orbit> = &parent._rocket;
123123
let request: &Request<'_> = &parent.request;
124-
// SAFETY: error_ptr is transmuted into the same type, with the same lifetime as the request.
125-
// It is kept alive by the erased response, so that the response type can borrow from it
124+
// SAFETY: TODO: error_ptr is transmuted into the same type, with the
125+
// same lifetime as the request.
126+
// It is kept alive by the erased response, so that the response
127+
// type can borrow from it
126128
dispatch(token, rocket, request, data, unsafe { transmute(&mut error_ptr)}).await
127129
};
128130

core/lib/src/lifecycle.rs

+19-6
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ async fn catch_handle<Fut, T, F>(name: Option<&str>, run: F) -> Option<T>
4444
.ok()
4545
}
4646

47+
pub(crate) fn error_ref<'r>(error_ptr: &'r mut Option<Box<dyn TypedError<'r> + 'r>>)
48+
-> Option<&'r dyn TypedError<'r>> {
49+
error_ptr.as_ref().map(|b| b.as_ref())
50+
}
51+
4752
impl Rocket<Orbit> {
4853
/// Preprocess the request for Rocket things. Currently, this means:
4954
///
@@ -112,21 +117,21 @@ impl Rocket<Orbit> {
112117
Outcome::Success(response) => response,
113118
Outcome::Error((status, error)) => {
114119
*error_ptr = error;
115-
self.dispatch_error(status, request, error_ptr.as_ref().map(|b| b.as_ref())).await
120+
self.dispatch_error(status, request, error_ref(error_ptr)).await
116121
},
117122
Outcome::Forward((_, status, error)) => {
118123
*error_ptr = error;
119-
self.dispatch_error(status, request, error_ptr.as_ref().map(|b| b.as_ref())).await
124+
self.dispatch_error(status, request, error_ref(error_ptr)).await
120125
},
121126
}
122127
}
123128
Outcome::Forward((_, status, error)) => {
124129
*error_ptr = error;
125-
self.dispatch_error(status, request, error_ptr.as_ref().map(|b| b.as_ref())).await
130+
self.dispatch_error(status, request, error_ref(error_ptr)).await
126131
},
127132
Outcome::Error((status, error)) => {
128133
*error_ptr = error;
129-
self.dispatch_error(status, request, error_ptr.as_ref().map(|b| b.as_ref())).await
134+
self.dispatch_error(status, request, error_ref(error_ptr)).await
130135
},
131136
};
132137

@@ -289,7 +294,11 @@ impl Rocket<Orbit> {
289294
let mut counter = 0;
290295
// Matches error [.source ...] type
291296
while error_copy.is_some() && counter < 5 {
292-
if let Some(catcher) = self.router.catch(status, req, error_copy.map(|e| e.trait_obj_typeid())) {
297+
if let Some(catcher) = self.router.catch(
298+
status,
299+
req,
300+
error_copy.map(|e| e.trait_obj_typeid())
301+
) {
293302
return self.invoke_specific_catcher(catcher, status, error_copy, req).await;
294303
}
295304
error_copy = error_copy.and_then(|e| e.source());
@@ -303,7 +312,11 @@ impl Rocket<Orbit> {
303312
let mut counter = 0;
304313
// Matches error [.source ...] type, and any status
305314
while error_copy.is_some() && counter < 5 {
306-
if let Some(catcher) = self.router.catch_any(status, req, error_copy.map(|e| e.trait_obj_typeid())) {
315+
if let Some(catcher) = self.router.catch_any(
316+
status,
317+
req,
318+
error_copy.map(|e| e.trait_obj_typeid())
319+
) {
307320
return self.invoke_specific_catcher(catcher, status, error_copy, req).await;
308321
}
309322
error_copy = error_copy.and_then(|e| e.source());

core/lib/src/local/asynchronous/request.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use std::fmt;
22

3+
use crate::lifecycle::error_ref;
34
use crate::request::RequestErrors;
45
use crate::{Request, Data};
56
use crate::http::{Status, Method};
@@ -89,7 +90,7 @@ impl<'c> LocalRequest<'c> {
8990
return LocalResponse::new(self.request, move |req, error_ptr| {
9091
// TODO: Ideally the RequestErrors should contain actual information.
9192
*error_ptr = Some(Box::new(RequestErrors::new(&[])));
92-
rocket.dispatch_error(Status::BadRequest, req, error_ptr.as_ref().map(|b| b.as_ref()))
93+
rocket.dispatch_error(Status::BadRequest, req, error_ref(error_ptr))
9394
}).await
9495
}
9596
}

core/lib/src/request/request.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ use crate::request::{FromParam, FromSegments, FromRequest, Outcome, AtomicMethod
1616
use crate::form::{self, ValueField, FromForm};
1717
use crate::data::Limits;
1818

19-
use crate::http::ProxyProto;
20-
use crate::http::{Method, Header, HeaderMap, ContentType, Accept, MediaType, CookieJar, Cookie, Status};
19+
use crate::http::{Method, Header, HeaderMap, ContentType, Accept, MediaType, CookieJar, Cookie,
20+
ProxyProto, Status};
2121
use crate::http::uri::{fmt::Path, Origin, Segments, Host, Authority};
2222
use crate::listener::{Certificates, Endpoint};
2323

core/lib/src/response/responder.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -498,13 +498,15 @@ impl<'r, 'o: 'r, R: ?Sized + ToOwned> Responder<'r, 'o> for std::borrow::Cow<'o,
498498
<<&'o R as Responder<'r, 'o>>::Error as Transient>::Transience: CanTranscendTo<Inv<'r>>,
499499
<R as ToOwned>::Owned: Responder<'r, 'o> + 'r,
500500
<<R as ToOwned>::Owned as Responder<'r, 'o>>::Error: Transient,
501-
<<<R as ToOwned>::Owned as Responder<'r, 'o>>::Error as Transient>::Transience: CanTranscendTo<Inv<'r>>,
501+
<<<R as ToOwned>::Owned as Responder<'r, 'o>>::Error as Transient>::Transience:
502+
CanTranscendTo<Inv<'r>>,
503+
// TODO: this atrocious formatting
502504
{
503505
type Error = Either<
504506
<&'o R as Responder<'r, 'o>>::Error,
505507
<R::Owned as Responder<'r, 'o>>::Error,
506508
>;
507-
509+
508510
fn respond_to(self, req: &'r Request<'_>) -> response::Outcome<'o, Self::Error> {
509511
match self {
510512
std::borrow::Cow::Borrowed(b) => b.respond_to(req).map_error(|e| Either::Left(e)),

core/lib/src/route/handler.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,10 @@ impl<'r, 'o: 'r> Outcome<'o> {
194194
match responder.respond_to(req) {
195195
response::Outcome::Success(response) => Outcome::Success(response),
196196
response::Outcome::Error(error) => {
197-
crate::trace::info!(type_name = std::any::type_name_of_val(&error), "Typed error to catch");
197+
crate::trace::info!(
198+
type_name = std::any::type_name_of_val(&error),
199+
"Typed error to catch"
200+
);
198201
Outcome::Error((error.status(), Some(Box::new(error))))
199202
},
200203
response::Outcome::Forward(status) => Outcome::Error((status, None)),

core/lib/src/router/router.rs

+9-3
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,18 @@ impl Router {
5656

5757
// For many catchers, using aho-corasick or similar should be much faster.
5858
// TODO: document difference between catch, and catch_any
59-
pub fn catch<'r>(&self, status: Status, req: &'r Request<'r>, error: Option<TypeId>) -> Option<&Catcher> {
59+
pub fn catch<'r>(&self, status: Status, req: &'r Request<'r>, error: Option<TypeId>)
60+
-> Option<&Catcher>
61+
{
6062
// Note that catchers are presorted by descending base length.
6163
self.catchers.get(&Some(status.code))
6264
.and_then(|c| c.iter().find(|c| c.matches(status, req, error)))
6365
}
6466

6567
// For many catchers, using aho-corasick or similar should be much faster.
66-
pub fn catch_any<'r>(&self, status: Status, req: &'r Request<'r>, error: Option<TypeId>) -> Option<&Catcher> {
68+
pub fn catch_any<'r>(&self, status: Status, req: &'r Request<'r>, error: Option<TypeId>)
69+
-> Option<&Catcher>
70+
{
6771
// Note that catchers are presorted by descending base length.
6872
self.catchers.get(&None)
6973
.and_then(|c| c.iter().find(|c| c.matches(status, req, error)))
@@ -556,7 +560,9 @@ mod test {
556560
router
557561
}
558562

559-
fn catcher<'a>(router: &'a Router, status: Status, uri: &str, error_ty: Option<TypeId>) -> Option<&'a Catcher> {
563+
fn catcher<'a>(router: &'a Router, status: Status, uri: &str, error_ty: Option<TypeId>)
564+
-> Option<&'a Catcher>
565+
{
560566
let client = Client::debug_with(vec![]).expect("client");
561567
let request = client.get(Origin::parse(uri).unwrap());
562568
router.catch(status, &request, error_ty)

docs/guide/05-requests.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2051,7 +2051,7 @@ on implementing [`Transient`] for custom error types.
20512051

20522052
* The form::Errors type does not (yet) implement Transient
20532053

2054-
The function arguement must be a reference to the error type expected. See the
2054+
The function arguement must be a reference to the error type expected. See the
20552055
[error handling example](@git/master/examples/error-handling)
20562056
for a full application, including the route that generates the error.
20572057

examples/error-handling/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,4 @@ publish = false
77

88
[dependencies]
99
rocket = { path = "../../core/lib" }
10-
transient = { path = "/home/matthew/transient" }
10+
transient = { path = "/code/matthew/transient" }

0 commit comments

Comments
 (0)