Skip to content

Dependency reuse

LucaCappelletti94 edited this page Oct 19, 2026 · 2 revisions

Install the main build described in Installation.

Search from a Rust workspace with dependency depth enabled.

cargo dejadoc --context-dependency-depth 1 --context-check-latest false

This also enables local context analysis. Add --functions for the separate function-duplicate check. Dependency matching uses --context-min-tokens, with a default of 30 weighted tokens.

Depth and selection

Depth is the shortest number of dependency edges from a selected local crate. The default depth is 0, which disables dependency discovery.

Depth Candidate sources
0 Selected workspace members, considered when dependency discovery is enabled
1 Direct dependencies of selected crates
2 and above Dependencies reachable through that many edges

When several workspace members are selected, their code can match across members at depth 0 without a dependency edge between them. A depth-zero finding can therefore describe repeated examples or sibling crates that cannot currently call each other.

Use --context-select to choose the local contexts to report. --context-search selects the workspace comparison corpus. Both accept workspace, crate:NAME, file:PATH, module:PATH and module-exact:PATH, as listed in Configuration. A module path includes the crate prefix, such as module:my_crate::parser.

cargo dejadoc --context-select workspace --context-dependency-depth 2 --context-check-latest false

For a single target, use crate:NAME with its compilation target name. Ordinary dependency edges are followed by default. --context-dev-dependencies and --context-build-dependencies add those edge kinds. --context-all-optional-dependencies explores optional paths outside the selected features, while --context-all-features enables all workspace features for Cargo discovery.

Interpret a finding

Each reuse group contains one local source range and its matching candidates.

action Source evidence Review needed
reuse-api A whole function or method has an established public route in a resolved package Dependency availability, signatures, types, features and behavior
upgrade-api A public route exists in a newer published package Upgrade compatibility and the candidate's requirements
request-extraction The match is internal code or an embedded block Whether a shared public helper would be useful upstream
unresolved Source analysis cannot establish accessibility Visibility, ownership and conditional-compilation facts

These are source-level matches. They do not prove that a candidate is a compiling replacement. For example, matching insert bodies in MySQL and SQLite examples can take different connection and schema types. A reuse-api finding at depth 0 also does not prove that a dependency edge exists.

For an internal match, dejadoc can provide a commit-pinned source link and a prefilled extraction-request link when the package declares a GitHub repository and the source range is verified. An established tagged request for the same range appears as existing_issue. Missing provenance or an unsuccessful lookup appears in lookup_warning. Following a prefilled link opens an issue form and creates no issue automatically.

The matching block in semver::parse::wildcard, for example, produces request-extraction when local code contains that private parser body. It requires upstream extraction or exposure before callers can use it as an API.

Check coverage and exit status

cargo dejadoc --context-dependency-depth 1 --context-check-latest false --json

Read reuse.coverage before treating an empty candidate list as a complete search.

Field Meaning
complete Every requested dependency analysis job completed
packages Distinct reached source packages, including workspace roots
indexed_files Source files examined through the index
cached_files Examined files whose canonical records came from a valid cache
failures Missing analysis that makes coverage incomplete
warnings Non-fatal cache, provenance or lookup diagnostics

Incomplete dependency coverage exits with 2, including with --no-fail. Reuse findings participate in exit status 1 only with --context-fail-on-reuse. Local duplicate groups retain their own gate. Configuration lists the full exit-status rules.

Features, targets and cache

Dependency discovery uses Cargo metadata without compiling the scanned project, and resolves dependencies through a temporary manifest mirror without writing the consumer's lockfile. Cargo configuration and toolchain selection still apply. --context-features, --context-no-default-features and --context-target control dependency discovery.

--context-check-latest defaults to true. It checks newer published versions and may download and index their sources. Set it to false to omit those version checks. This does not disable source downloads or GitHub provenance and issue lookups, and Cargo's offline setting does not disable dejadoc's own HTTP requests.

The default cache is $XDG_CACHE_HOME/dejadoc, or $HOME/.cache/dejadoc when XDG_CACHE_HOME is unset or empty. --context-cache-dir chooses another directory. Public crates.io indexes can be shared across projects only when the installed sources match the published artifact. Path, Git, alternate-registry and modified-source entries remain private.

A warm cache avoids rebuilding canonical records, but discovery, parsing, hashing and cache loading still have a cost. See Performance for measured time and memory, and GitHub Action for the public-cache boundary in CI.

Clone this wiki locally