@@ -117,7 +117,8 @@ impl fmt::Debug for DebugListRewrite<'_> {
117
117
/// - [`FileServer::map_file()`]
118
118
pub trait Rewriter : Send + Sync + ' static {
119
119
/// Alter the [`FileResponse`] as needed.
120
- fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > ) -> Option < FileResponse < ' p , ' h > > ;
120
+ fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > )
121
+ -> Option < FileResponse < ' p , ' h > > ;
121
122
}
122
123
123
124
/// A Response from a [`FileServer`]
@@ -193,7 +194,9 @@ impl<'p, 'h> File<'p, 'h> {
193
194
// FileResponse::Redirect(Redirect::permanent(f(self.full_uri.clone().into_owned())))
194
195
// }
195
196
196
- async fn respond_to < ' r > ( self , req : & ' r Request < ' _ > , data : Data < ' r > ) -> Outcome < ' r > where ' h : ' r {
197
+ async fn respond_to < ' r > ( self , req : & ' r Request < ' _ > , data : Data < ' r > ) -> Outcome < ' r >
198
+ where ' h : ' r
199
+ {
197
200
/// Normalize paths to enable `file_root` to work properly
198
201
fn strip_trailing_slash ( p : & Path ) -> & Path {
199
202
let bytes = p. as_os_str ( ) . as_encoded_bytes ( ) ;
@@ -223,17 +226,24 @@ impl<'p, 'h> File<'p, 'h> {
223
226
}
224
227
225
228
impl < F : Send + Sync + ' static > Rewriter for F
226
- where F : for <' r , ' h > Fn ( Option < FileResponse < ' r , ' h > > , & Request < ' _ > ) -> Option < FileResponse < ' r , ' h > >
229
+ where F : for <' r , ' h > Fn ( Option < FileResponse < ' r , ' h > > , & Request < ' _ > )
230
+ -> Option < FileResponse < ' r , ' h > >
227
231
{
228
- fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > ) -> Option < FileResponse < ' p , ' h > > {
232
+ fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > )
233
+ -> Option < FileResponse < ' p , ' h > >
234
+ {
229
235
self ( path, req)
230
236
}
231
237
}
232
238
233
239
/// Helper to implement [`FileServer::filter_file()`]
234
240
struct FilterFile < F > ( F ) ;
235
- impl < F : Fn ( & File < ' _ , ' _ > , & Request < ' _ > ) -> bool + Send + Sync + ' static > Rewriter for FilterFile < F > {
236
- fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > ) -> Option < FileResponse < ' p , ' h > > {
241
+ impl < F > Rewriter for FilterFile < F >
242
+ where F : Fn ( & File < ' _ , ' _ > , & Request < ' _ > ) -> bool + Send + Sync + ' static
243
+ {
244
+ fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > )
245
+ -> Option < FileResponse < ' p , ' h > >
246
+ {
237
247
match path {
238
248
Some ( FileResponse :: File ( file) ) if !self . 0 ( & file, req) => None ,
239
249
path => path,
@@ -244,9 +254,12 @@ impl<F: Fn(&File<'_, '_>, &Request<'_>) -> bool + Send + Sync + 'static> Rewrite
244
254
/// Helper to implement [`FileServer::map_file()`]
245
255
struct MapFile < F > ( F ) ;
246
256
impl < F > Rewriter for MapFile < F >
247
- where F : for < ' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > ) -> FileResponse < ' p , ' h > + Send + Sync + ' static ,
257
+ where F : for < ' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > )
258
+ -> FileResponse < ' p , ' h > + Send + Sync + ' static ,
248
259
{
249
- fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > ) -> Option < FileResponse < ' p , ' h > > {
260
+ fn rewrite < ' p , ' h > ( & self , path : Option < FileResponse < ' p , ' h > > , req : & Request < ' _ > )
261
+ -> Option < FileResponse < ' p , ' h > >
262
+ {
250
263
match path {
251
264
Some ( FileResponse :: File ( file) ) => Some ( self . 0 ( file, req) ) ,
252
265
path => path,
@@ -274,7 +287,8 @@ impl<F> Rewriter for MapFile<F>
274
287
/// Panics if `path` does not exist. See [`file_root_permissive`] for a
275
288
/// non-panicing variant.
276
289
pub fn dir_root ( path : impl AsRef < Path > )
277
- -> impl for <' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > ) -> FileResponse < ' p , ' h > + Send + Sync + ' static
290
+ -> impl for <' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > )
291
+ -> FileResponse < ' p , ' h > + Send + Sync + ' static
278
292
{
279
293
let path = path. as_ref ( ) ;
280
294
if !path. is_dir ( ) {
@@ -306,7 +320,8 @@ pub fn dir_root(path: impl AsRef<Path>)
306
320
/// Panics if `path` does not exist. See [`file_root_permissive`] for a
307
321
/// non-panicing variant.
308
322
pub fn file_root ( path : impl AsRef < Path > )
309
- -> impl for <' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > ) -> FileResponse < ' p , ' h > + Send + Sync + ' static
323
+ -> impl for <' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > )
324
+ -> FileResponse < ' p , ' h > + Send + Sync + ' static
310
325
{
311
326
let path = path. as_ref ( ) ;
312
327
if !path. exists ( ) {
@@ -334,7 +349,8 @@ pub fn file_root(path: impl AsRef<Path>)
334
349
/// # }
335
350
/// ```
336
351
pub fn file_root_permissive ( path : impl AsRef < Path > )
337
- -> impl for <' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > ) -> FileResponse < ' p , ' h > + Send + Sync + ' static
352
+ -> impl for <' p , ' h > Fn ( File < ' p , ' h > , & Request < ' _ > )
353
+ -> FileResponse < ' p , ' h > + Send + Sync + ' static
338
354
{
339
355
let path = path. as_ref ( ) . to_path_buf ( ) ;
340
356
move |f, _r| {
@@ -477,7 +493,8 @@ impl FileServer {
477
493
///
478
494
/// Redirects all requests that have been filtered to the root of the `FileServer`.
479
495
/// ```rust,no_run
480
- /// # use rocket::{fs::{FileServer, FileResponse}, response::Redirect, uri, Build, Rocket, Request};
496
+ /// # use rocket::{fs::{FileServer, FileResponse}, response::Redirect,
497
+ /// # uri, Build, Rocket, Request};
481
498
/// fn redir_missing<'p, 'h>(p: Option<FileResponse<'p, 'h>>, _req: &Request<'_>)
482
499
/// -> Option<FileResponse<'p, 'h>>
483
500
/// {
@@ -533,12 +550,14 @@ impl FileServer {
533
550
/// rocket::build()
534
551
/// .mount(
535
552
/// "/",
536
- /// FileServer::from("static").map_file(|f, _r| f.map_path(|p| p.join("hidden")).into())
553
+ /// FileServer::from("static")
554
+ /// .map_file(|f, _r| f.map_path(|p| p.join("hidden")).into())
537
555
/// )
538
556
/// # }
539
557
/// ```
540
558
pub fn map_file < F > ( self , f : F ) -> Self
541
- where F : for < ' r , ' h > Fn ( File < ' r , ' h > , & Request < ' _ > ) -> FileResponse < ' r , ' h > + Send + Sync + ' static
559
+ where F : for < ' r , ' h > Fn ( File < ' r , ' h > , & Request < ' _ > )
560
+ -> FileResponse < ' r , ' h > + Send + Sync + ' static
542
561
{
543
562
self . and_rewrite ( MapFile ( f) )
544
563
}
0 commit comments