fn list(&self) -> impl Filter<Extract = impl Reply, Error = warp::Rejection> + Clone {
        /// Query parameter matcher.
        ///
        /// The actual value of the query parameter does not matter and is never accessed. It only
        /// matters whether it is given (`?list`, `?list=`, `?list=abc`).
        #[derive(Deserialize)]
        struct QueryParameters {
            // This field is never accessed but is required for the tag
            #[allow(dead_code)]
            list: String,
        }
        /// Data for `list.html.hbs`.
        #[derive(Serialize)]
        struct TemplateListData {
            /// Path of the listed directory.
            path: String,
            /// Link to the parent directory if it exist (the listed directory is not the root).
            parent_list_link: Option<String>,
            /// List of all the items in the directory.
            children: Vec<TemplateListChildData>,
        }
        /// A list item.
        #[derive(Serialize)]
        struct TemplateListChildData {
            /// Link to the item.
            link: String,
            /// Name of the item.
            name: String,
        }
        /// Data for `list_not_found.html.hbs`.
        #[derive(Serialize)]
        struct TemplateListNotFoundData {
            path: String,
        }
        warp::get2()
            .and(
                warp::path::full().map(|fullpath: warp::filters::path::FullPath| {
                    Path::from_percent_encoded(fullpath.as_str().to_string().as_bytes())
                }),
            )
            .and(warp::query::<QueryParameters>())
            .and(self.templates())
            .and(self.config())
            .and_then(
                |path: Path,
                 _: QueryParameters,
                 templates: Arc<Handlebars>,
                 config: Arc<Config>|
                 -> Result<Response<Vec<u8>>, Rejection> {
                    let repo = GitRepository::new(&config.repo)?;
                    let item = repo.item(path.clone())?;

                    match item.list() {
                        Ok(items) => Ok(ResponseBuilder::new().status(200).body_template(
                            &templates,
                            "list.html",
                            &TemplateListData {
                                path: PathStringBuilder::new(path.clone()).dir(true).build_lossy(),
                                parent_list_link: path.clone().parent().map(|path| {
                                    format!(
                                        "{}?list",
                                        PathStringBuilder::new(path)
                                            .root(true)
                                            .build_percent_encode()
                                    )
                                }),
                                children: items
                                    .iter()
                                    .sorted_by(|a, b| {
                                        // Error handling instead of unwrap would be preferable but
                                        // horrible in this situation. There should be no errors
                                        // anyways; the files have to exist (the only reasonable
                                        // error source).
                                        if a.is_dir().unwrap() && b.is_file().unwrap() {
                                            Ordering::Less
                                        } else if a.is_file().unwrap() && b.is_dir().unwrap() {
                                            Ordering::Greater
                                        } else {
                                            // Unwrap because the root cannot be one of the listed
                                            // items.
                                            a.path()
                                                .filename()
                                                .unwrap()
                                                .bytes()
                                                .cmp(b.path().filename().unwrap().bytes())
                                        }
                                    })
                                    .map(|item| -> Result<TemplateListChildData, GitError> {
                                        let link = if item.is_dir()? {
                                            format!(
                                                "{}?list",
                                                PathStringBuilder::new(item.path().clone())
                                                    .root(true)
                                                    .build_percent_encode()
                                            )
                                        } else {
                                            PathStringBuilder::new(item.path().clone())
                                                .root(true)
                                                .build_percent_encode()
                                        };
                                        Ok(TemplateListChildData {
                                            link: link,
                                            name: PathStringBuilder::new(
                                                // A child of something has to have a filename
                                                item.path().filename().unwrap(),
                                            )
                                            .dir(item.is_dir()?)
                                            .build_lossy(),
                                        })
                                    })
                                    // A list of results can be collected to a result of a list.
                                    .collect::<Result<Vec<_>, _>>()?,
                            },
                        )?),
                        Err(GitError::NotFound) => {
                            Ok(ResponseBuilder::new().status(200).body_template(
                                &templates,
                                "list_not_found.html",
                                &TemplateListNotFoundData {
                                    path: PathStringBuilder::new(path).dir(true).build_lossy(),
                                },
                            )?)
                        }
                        Err(GitError::IsFile) => Ok(ResponseBuilder::new().redirect(path)),
                        Err(err) => Err(err.into()),
                    }
                },
            )
    }
/// Serves a page listing all files in a directory. Matches any URL with a `list` query
/// paramter.
///
/// If the directory does not exist a 404 page is served. If the path points to a file a
/// redirect is added.
///
/// Directories are sorted first.
Serves a page listing all files in a directory. Matches any URL with a `list` query
paramter.

If the directory does not exist a 404 page is served. If the path points to a file a
redirect is added.

Directories are sorted first.
Serves a page listing all files in a directory . Matches any URL with a ` list ` query paramter . If the directory does not exist a 404 page is served . If the path points to a file a redirect is added . Directories are sorted first .
fn list(&self) -> impl Filter<Extract = impl Reply, Error = warp::Rejection> + Clone {
        /// Query parameter matcher.
        ///
        /// The actual value of the query parameter does not matter and is never accessed. It only
        /// matters whether it is given (`?list`, `?list=`, `?list=abc`).
        #[derive(Deserialize)]
        struct QueryParameters {
            // This field is never accessed but is required for the tag
            #[allow(dead_code)]
            list: String,
        }
        /// Data for `list.html.hbs`.
        #[derive(Serialize)]
        struct TemplateListData {
            /// Path of the listed directory.
            path: String,
            /// Link to the parent directory if it exist (the listed directory is not the root).
            parent_list_link: Option<String>,
            /// List of all the items in the directory.
            children: Vec<TemplateListChildData>,
        }
        /// A list item.
        #[derive(Serialize)]
        struct TemplateListChildData {
            /// Link to the item.
            link: String,
            /// Name of the item.
            name: String,
        }
        /// Data for `list_not_found.html.hbs`.
        #[derive(Serialize)]
        struct TemplateListNotFoundData {
            path: String,
        }
        warp::get2()
            .and(
                warp::path::full().map(|fullpath: warp::filters::path::FullPath| {
                    Path::from_percent_encoded(fullpath.as_str().to_string().as_bytes())
                }),
            )
            .and(warp::query::<QueryParameters>())
            .and(self.templates())
            .and(self.config())
            .and_then(
                |path: Path,
                 _: QueryParameters,
                 templates: Arc<Handlebars>,
                 config: Arc<Config>|
                 -> Result<Response<Vec<u8>>, Rejection> {
                    let repo = GitRepository::new(&config.repo)?;
                    let item = repo.item(path.clone())?;
                    match item.list() {
                        Ok(items) => Ok(ResponseBuilder::new().status(200).body_template(
                            &templates,
                            "list.html",
                            &TemplateListData {
                                path: PathStringBuilder::new(path.clone()).dir(true).build_lossy(),
                                parent_list_link: path.clone().parent().map(|path| {
                                    format!(
                                        "{}?list",
                                        PathStringBuilder::new(path)
                                            .root(true)
                                            .build_percent_encode()
                                    )
                                }),
                                children: items
                                    .iter()
                                    .sorted_by(|a, b| {
                                        // Error handling instead of unwrap would be preferable but
                                        // horrible in this situation. There should be no errors
                                        // anyways; the files have to exist (the only reasonable
                                        // error source).
                                        if a.is_dir().unwrap() && b.is_file().unwrap() {
                                            Ordering::Less
                                        } else if a.is_file().unwrap() && b.is_dir().unwrap() {
                                            Ordering::Greater
                                        } else {
                                            // Unwrap because the root cannot be one of the listed
                                            // items.
                                            a.path()
                                                .filename()
                                                .unwrap()
                                                .bytes()
                                                .cmp(b.path().filename().unwrap().bytes())
                                        }
                                    })
                                    .map(|item| -> Result<TemplateListChildData, GitError> {
                                        let link = if item.is_dir()? {
                                            format!(
                                                "{}?list",
                                                PathStringBuilder::new(item.path().clone())
                                                    .root(true)
                                                    .build_percent_encode()
                                            )
                                        } else {
                                            PathStringBuilder::new(item.path().clone())
                                                .root(true)
                                                .build_percent_encode()
                                        };
                                        Ok(TemplateListChildData {
                                            link: link,
                                            name: PathStringBuilder::new(
                                                // A child of something has to have a filename
                                                item.path().filename().unwrap(),
                                            )
                                            .dir(item.is_dir()?)
                                            .build_lossy(),
                                        })
                                    })
                                    // A list of results can be collected to a result of a list.
                                    .collect::<Result<Vec<_>, _>>()?,
                            },
                        )?),
                        Err(GitError::NotFound) => {
                            Ok(ResponseBuilder::new().status(200).body_template(
                                &templates,
                                "list_not_found.html",
                                &TemplateListNotFoundData {
                                    path: PathStringBuilder::new(path).dir(true).build_lossy(),
                                },
                            )?)
                        }
                        Err(GitError::IsFile) => Ok(ResponseBuilder::new().redirect(path)),
                        Err(err) => Err(err.into()),
                    }
                },
            )
    }
fn list ( & self ) -> impl Filter < Extract = impl Reply , Error = warp :: Rejection > + Clone { /// Query parameter matcher. /// /// The actual value of the query parameter does not matter and is never accessed. It only /// matters whether it is given (`?list`, `?list=`, `?list=abc`). # [ derive ( Deserialize ) ] struct QueryParameters { // This field is never accessed but is required for the tag # [ allow ( dead_code ) ] list : String , } /// Data for `list.html.hbs`. # [ derive ( Serialize ) ] struct TemplateListData { /// Path of the listed directory. path : String , /// Link to the parent directory if it exist (the listed directory is not the root). parent_list_link : Option < String > , /// List of all the items in the directory. children : Vec < TemplateListChildData > , } /// A list item. # [ derive ( Serialize ) ] struct TemplateListChildData { /// Link to the item. link : String , /// Name of the item. name : String , } /// Data for `list_not_found.html.hbs`. # [ derive ( Serialize ) ] struct TemplateListNotFoundData { path : String , } warp :: get2 ( ) . and ( warp :: path :: full ( ) . map ( | fullpath : warp :: filters :: path :: FullPath | { Path :: from_percent_encoded ( fullpath . as_str ( ) . to_string ( ) . as_bytes ( ) ) } ) , ) . and ( warp :: query :: < QueryParameters > ( ) ) . and ( self . templates ( ) ) . and ( self . config ( ) ) . and_then ( | path : Path , _ : QueryParameters , templates : Arc < Handlebars > , config : Arc < Config > | -> Result < Response < Vec < u8 > > , Rejection > { let repo = GitRepository :: new ( & config . repo ) ? ; let item = repo . item ( path . clone ( ) ) ? ; match item . list ( ) { Ok ( items ) => Ok ( ResponseBuilder :: new ( ) . status ( 200 ) . body_template ( & templates , " " , & TemplateListData { path : PathStringBuilder :: new ( path . clone ( ) ) . dir ( true ) . build_lossy ( ) , parent_list_link : path . clone ( ) . parent ( ) . map ( | path | { format ! ( " " PathStringBuilder new ( path ) root ( true ) build_percent_encode ( ) ) } ) , children : items . iter ( ) . sorted_by ( | a , b | { // Error handling instead of unwrap would be preferable but // horrible in this situation. There should be no errors // anyways; the files have to exist (the only reasonable // error source). if a . is_dir ( ) . unwrap ( ) && b . is_file ( ) . unwrap ( ) { Ordering :: Less } else if a . is_file ( ) . unwrap ( ) && b . is_dir ( ) . unwrap ( ) { Ordering :: Greater } else { // Unwrap because the root cannot be one of the listed // items. a . path ( ) . filename ( ) . unwrap ( ) . bytes ( ) . cmp ( b . path ( ) . filename ( ) . unwrap ( ) . bytes ( ) ) } } ) . map ( | item | -> Result < TemplateListChildData , GitError > { let link = if item . is_dir ( ) ? { format ! ( " " PathStringBuilder new ( item path ( ) clone ( ) ) root ( true ) build_percent_encode ( ) ) } else { PathStringBuilder :: new ( item . path ( ) . clone ( ) ) . root ( true ) . build_percent_encode ( ) } ; Ok ( TemplateListChildData { link : link , name : PathStringBuilder :: new ( // A child of something has to have a filename item . path ( ) . filename ( ) . unwrap ( ) , ) . dir ( item . is_dir ( ) ? ) . build_lossy ( ) , } ) } ) // A list of results can be collected to a result of a list. . collect :: < Result < Vec < _ > , _ > > ( ) ? , } , ) ? ) , Err ( GitError :: NotFound ) => { Ok ( ResponseBuilder :: new ( ) . status ( 200 ) . body_template ( & templates , " " , & TemplateListNotFoundData { path : PathStringBuilder :: new ( path ) . dir ( true ) . build_lossy ( ) , } , ) ? ) } Err ( GitError :: IsFile ) => Ok ( ResponseBuilder :: new ( ) . redirect ( path ) ) , Err ( err ) => Err ( err . into ( ) ) , } } , ) }
Serves a page listing all files in a directory.
Serves a page listing all files in a directory .
&self
&self