Skip to main content

url_parts

Function url_parts 

Source
fn url_parts(
    cache: &Cache,
    def_id: DefId,
    module_fqp: &[Symbol],
    relative_to: &[Symbol],
    jump_to_def_path_depth: Option<usize>,
) -> Result<(UrlPartsBuilder, bool), HrefError>
Expand description

Returns (url_parts, is_remote) where is_remote indicates the URL points to an external location and should not use relative URLs.

This function tries to generate minimal, relative URLs. When generating an intra-doc link from one item page to another, it compares the paths of both items and generates exactly the right number of “../”’s to reach the deepest common parent, then fills in the rest of the path. This is done by comparing module_fqp with relative_to.

When generating a link for jump-to-def across crates, that won’t work, because sources are stored under src/<crate>/<path>.rs. When linking jump-to-def for another crate, we just write enough “../”’s to reach the doc root, then generate the entire path for module_fqp. The right number of “../”’s is stored in jump_to_def_path_depth.