Skip to content

Commit 914e857

Browse files
the10thWizSergioBenitez
authored andcommitted
Fix line length
1 parent 548bed1 commit 914e857

File tree

2 files changed

+41
-17
lines changed

2 files changed

+41
-17
lines changed

core/lib/src/fs/server.rs

+33-14
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ impl fmt::Debug for DebugListRewrite<'_> {
117117
/// - [`FileServer::map_file()`]
118118
pub trait Rewriter: Send + Sync + 'static {
119119
/// 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>>;
121122
}
122123

123124
/// A Response from a [`FileServer`]
@@ -193,7 +194,9 @@ impl<'p, 'h> File<'p, 'h> {
193194
// FileResponse::Redirect(Redirect::permanent(f(self.full_uri.clone().into_owned())))
194195
// }
195196

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+
{
197200
/// Normalize paths to enable `file_root` to work properly
198201
fn strip_trailing_slash(p: &Path) -> &Path {
199202
let bytes = p.as_os_str().as_encoded_bytes();
@@ -223,17 +226,24 @@ impl<'p, 'h> File<'p, 'h> {
223226
}
224227

225228
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>>
227231
{
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+
{
229235
self(path, req)
230236
}
231237
}
232238

233239
/// Helper to implement [`FileServer::filter_file()`]
234240
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+
{
237247
match path {
238248
Some(FileResponse::File(file)) if !self.0(&file, req) => None,
239249
path => path,
@@ -244,9 +254,12 @@ impl<F: Fn(&File<'_, '_>, &Request<'_>) -> bool + Send + Sync + 'static> Rewrite
244254
/// Helper to implement [`FileServer::map_file()`]
245255
struct MapFile<F>(F);
246256
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,
248259
{
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+
{
250263
match path {
251264
Some(FileResponse::File(file)) => Some(self.0(file, req)),
252265
path => path,
@@ -274,7 +287,8 @@ impl<F> Rewriter for MapFile<F>
274287
/// Panics if `path` does not exist. See [`file_root_permissive`] for a
275288
/// non-panicing variant.
276289
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
278292
{
279293
let path = path.as_ref();
280294
if !path.is_dir() {
@@ -306,7 +320,8 @@ pub fn dir_root(path: impl AsRef<Path>)
306320
/// Panics if `path` does not exist. See [`file_root_permissive`] for a
307321
/// non-panicing variant.
308322
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
310325
{
311326
let path = path.as_ref();
312327
if !path.exists() {
@@ -334,7 +349,8 @@ pub fn file_root(path: impl AsRef<Path>)
334349
/// # }
335350
/// ```
336351
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
338354
{
339355
let path = path.as_ref().to_path_buf();
340356
move |f, _r| {
@@ -477,7 +493,8 @@ impl FileServer {
477493
///
478494
/// Redirects all requests that have been filtered to the root of the `FileServer`.
479495
/// ```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};
481498
/// fn redir_missing<'p, 'h>(p: Option<FileResponse<'p, 'h>>, _req: &Request<'_>)
482499
/// -> Option<FileResponse<'p, 'h>>
483500
/// {
@@ -533,12 +550,14 @@ impl FileServer {
533550
/// rocket::build()
534551
/// .mount(
535552
/// "/",
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())
537555
/// )
538556
/// # }
539557
/// ```
540558
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
542561
{
543562
self.and_rewrite(MapFile(f))
544563
}

core/lib/tests/file_server.rs

+8-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ use rocket::{Rocket, Route, Build};
55
use rocket::http::Status;
66
use rocket::local::blocking::Client;
77
use rocket::fs::{
8-
dir_root, file_root, filter_dotfiles, index, file_root_permissive, normalize_dirs, relative, FileServer
8+
dir_root,
9+
file_root,
10+
filter_dotfiles,
11+
index,
12+
file_root_permissive,
13+
normalize_dirs,
14+
relative,
15+
FileServer
916
};
1017

1118
fn static_root() -> &'static Path {
@@ -60,14 +67,12 @@ fn rocket() -> Rocket<Build> {
6067
FileServer::empty()
6168
.filter_file(filter_dotfiles)
6269
.map_file(file_root(root.join("other/hello.txt")))
63-
6470
)
6571
.mount(
6672
"/missing_root",
6773
FileServer::empty()
6874
.filter_file(filter_dotfiles)
6975
.map_file(file_root_permissive(root.join("no_file")))
70-
7176
)
7277
}
7378

0 commit comments

Comments
 (0)