pub struct DepGraph { /* private fields */ }Expand description
Directed link/embed edges between pages, keyed by source path.
Built once per build via DepGraph::build; queried via DepGraph::backlinks
and DepGraph::back_embeds. Embed edges are a subset already present
in forward_links/backlinks — forward_embeds/back_embeds narrow to
just LinkType::Embed because embeds are more render-relevant than plain
links (a transcluded page’s body IS part of the embedding page’s output).
Implementations§
Source§impl DepGraph
impl DepGraph
Sourcepub fn build<'a, I>(pages: I) -> Self
pub fn build<'a, I>(pages: I) -> Self
Build a DepGraph from each page’s source path and the outgoing
links it resolved during parsing. Order of pages does not affect
the result — edge lists within a bucket follow input order for
determinism, but no page’s presence depends on any other’s.
Sourcepub fn with_embed_pairs<'a, I>(self, pairs: I) -> Self
pub fn with_embed_pairs<'a, I>(self, pairs: I) -> Self
Fold in transclusion edges recorded by the resolve phase (moss#922 Stage 7).
pairs are (target, immediate_embedder) — exactly the shape
ResolveResult::embed_deps produces (resolve/embeds.rs), i.e. DIRECT
one-hop edges: for index.md embedding a.md embedding b.md the
resolver reports [("a.md", "index.md"), ("b.md", "a.md")]. The second
element is the file the marker was found in, NOT the top-level page
being resolved, so grouping by it yields a correct adjacency list and
multi-hop chains are answered by Self::embed_closure, never by
filtering pairs on the page under test (which would silently miss
b.md as a dependency of index.md).
This exists as a separate builder step, ContentGraph::with_output_overrides
style, because these edges are produced by a different phase than
outgoing_links: transclusion is spliced from disk bytes during resolve,
before the AST dispatcher that populates outgoing_links ever runs, so
no page→page LinkType::Embed link exists to carry them.
Duplicate edges (the same nested pair is reported once per ancestor that transitively embeds it) are collapsed.
Sourcepub fn embed_closure(&self, path: &str) -> Vec<String>
pub fn embed_closure(&self, path: &str) -> Vec<String>
Every file whose bytes are spliced into path’s markdown, transitively.
A breadth-first walk of forward_embeds from path, excluding path
itself, bounded by MAX_EMBED_DEPTH — the same limit
resolve_embeds_inner stops recursing at, so the closure never claims a
dependency on content the resolver refused to splice. Cycles terminate
on the visited set.
This is the parse cache’s validity input (moss#922 Stage 7): path’s
cached ParsedDocument is only reusable if every member of this set
still hashes to what it hashed to when the entry was written.
Sourcepub fn forward_links(&self, path: &str) -> &[String]
pub fn forward_links(&self, path: &str) -> &[String]
Pages path links to (any LinkType), in resolution order. Empty if
path has no outgoing links or is not a source in this graph.
Sourcepub fn forward_embeds(&self, path: &str) -> &[String]
pub fn forward_embeds(&self, path: &str) -> &[String]
Pages path embeds (LinkType::Embed only). Subset of forward_links.
Sourcepub fn backlinks(&self, path: &str) -> &[String]
pub fn backlinks(&self, path: &str) -> &[String]
Pages that link to path (any LinkType). Empty if nothing links here.
Sourcepub fn back_embeds(&self, path: &str) -> &[String]
pub fn back_embeds(&self, path: &str) -> &[String]
Pages that embed path (LinkType::Embed only). Subset of backlinks.