fn path_for_version(
    req_path: &[&str],
    known_platforms: &[String],
    storage: &Storage,
    config: &Config,
) -> String {
    // Simple case: page exists in the latest version, so just change the version number
    if File::from_path(storage, &req_path.join("/"), config).is_ok() {
        // NOTE: this adds 'index.html' if it wasn't there before
        return req_path[3..].join("/");
    }
    // check if req_path[3] is the platform choice or the name of the crate
    // Note we don't require the platform to have a trailing slash.
    let platform = if known_platforms.iter().any(|s| s == req_path[3]) && req_path.len() >= 4 {
        req_path[3]
    } else {
        ""
    };
    let is_source_view = if platform.is_empty() {
        // /{name}/{version}/src/{crate}/index.html
        req_path.get(3).copied() == Some("src")
    } else {
        // /{name}/{version}/{platform}/src/{crate}/index.html
        req_path.get(4).copied() == Some("src")
    };
    // this page doesn't exist in the latest version
    let last_component = *req_path.last().unwrap();
    let search_item = if last_component == "index.html" {
        // this is a module
        req_path.get(req_path.len() - 2).copied()
    // no trailing slash; no one should be redirected here but we handle it gracefully anyway
    } else if last_component == platform {
        // nothing to search for
        None
    } else if !is_source_view {
        // this is an item
        last_component.split('.').nth(1)
    } else {
        // this is a source file; try searching for the module
        Some(last_component.strip_suffix(".rs.html").unwrap())
    };
    if let Some(search) = search_item {
        format!("{}?search={}", platform, search)
    } else {
        platform.to_owned()
    }
}
/// Checks whether the given path exists.
/// The crate's `target_name` is used to confirm whether a platform triple is part of the path.
///
/// Note that path is overloaded in this context to mean both the path of a URL
/// and the file path of a static file in the DB.
///
/// `req_path` is assumed to have the following format:
/// `rustdoc/crate/version[/platform]/module/[kind.name.html|index.html]`
///
/// Returns a path that can be appended to `/crate/version/` to create a complete URL.
Checks whether the given path exists.
The crate's `target_name` is used to confirm whether a platform triple is part of the path.

Note that path is overloaded in this context to mean both the path of a URL
and the file path of a static file in the DB.



Returns a path that can be appended to `/crate/version/` to create a complete URL.
Checks whether the given path exists . The crate ' s ` target_name ` is used to confirm whether a platform triple is part of the path . Note that path is overloaded in this context to mean both the path of a URL and the file path of a static file in the DB . Returns a path that can be appended to ` / crate / version / ` to create a complete URL .
fn path_for_version(
    req_path: &[&str],
    known_platforms: &[String],
    storage: &Storage,
    config: &Config,
) -> String {
    // Simple case: page exists in the latest version, so just change the version number
    if File::from_path(storage, &req_path.join("/"), config).is_ok() {
        // NOTE: this adds 'index.html' if it wasn't there before
        return req_path[3..].join("/");
    }
    // check if req_path[3] is the platform choice or the name of the crate
    // Note we don't require the platform to have a trailing slash.
    let platform = if known_platforms.iter().any(|s| s == req_path[3]) && req_path.len() >= 4 {
        req_path[3]
    } else {
        ""
    };
    let is_source_view = if platform.is_empty() {
        // /{name}/{version}/src/{crate}/index.html
        req_path.get(3).copied() == Some("src")
    } else {
        // /{name}/{version}/{platform}/src/{crate}/index.html
        req_path.get(4).copied() == Some("src")
    };
    // this page doesn't exist in the latest version
    let last_component = *req_path.last().unwrap();
    let search_item = if last_component == "index.html" {
        // this is a module
        req_path.get(req_path.len() - 2).copied()
    // no trailing slash; no one should be redirected here but we handle it gracefully anyway
    } else if last_component == platform {
        // nothing to search for
        None
    } else if !is_source_view {
        // this is an item
        last_component.split('.').nth(1)
    } else {
        // this is a source file; try searching for the module
        Some(last_component.strip_suffix(".rs.html").unwrap())
    };
    if let Some(search) = search_item {
        format!("{}?search={}", platform, search)
    } else {
        platform.to_owned()
    }
}
fn path_for_version ( req_path : & [ & str ] , known_platforms : & [ String ] , storage : & Storage , config : & Config , ) -> String { // Simple case: page exists in the latest version, so just change the version number if File :: from_path ( storage , & req_path . join ( " " ) , config ) . is_ok ( ) { // NOTE: this adds 'index.html' if it wasn't there before return req_path [ 3 .. ] . join ( " " ) ; } // check if req_path[3] is the platform choice or the name of the crate // Note we don't require the platform to have a trailing slash. let platform = if known_platforms . iter ( ) . any ( | s | s == req_path [ 3 ] ) && req_path . len ( ) >= 4 { req_path [ 3 ] } else { " " } ; let is_source_view = if platform . is_empty ( ) { // /{name}/{version}/src/{crate}/index.html req_path . get ( 3 ) . copied ( ) == Some ( " " ) } else { // /{name}/{version}/{platform}/src/{crate}/index.html req_path . get ( 4 ) . copied ( ) == Some ( " " ) } ; // this page doesn't exist in the latest version let last_component = * req_path . last ( ) . unwrap ( ) ; let search_item = if last_component == " " { // this is a module req_path . get ( req_path . len ( ) - 2 ) . copied ( ) // no trailing slash; no one should be redirected here but we handle it gracefully anyway } else if last_component == platform { // nothing to search for None } else if ! is_source_view { // this is an item last_component . split ( '.' ) . nth ( 1 ) } else { // this is a source file; try searching for the module Some ( last_component . strip_suffix ( " " ) . unwrap ( ) ) } ; if let Some ( search ) = search_item { format ! ( " " platform search ) } else { platform . to_owned ( ) } }
Checks whether the given path exists.
Checks whether the given path exists .
req_path
&[&str]
known_platforms
&[String]
storage
&Storage
config
&Config
req_path
&[&str]
known_platforms
&[String]
storage
&Storage
config
&Config