pub struct PackageGraph { /* private fields */ }
Expand description

A graph of packages and dependencies between them, parsed from metadata returned by cargo metadata.

For examples on how to use PackageGraph, see the examples directory in this crate.

Implementations

Returns a derived graph representing every feature of every package.

The feature graph is constructed the first time this method is called. The graph is cached so that repeated calls to this method are cheap.

Executes the given MetadataCommand and constructs a PackageGraph from it.

Parses the given Metadata and constructs a PackageGraph from it.

Constructs a package graph from the given JSON output of cargo metadata.

Generally, guppy expects the cargo metadata command to be run with --all-features, so that guppy has a full view of the dependency graph.

For full functionality, cargo metadata should be run without --no-deps, so that guppy knows about third-party crates and dependency edges. However, guppy supports a “light” mode if --no-deps is run, in which case the following limitations will apply:

  • dependency queries will not work
  • there will be no information about non-workspace crates

Returns information about the workspace.

Returns an iterator over all the package IDs in this graph.

Returns an iterator over all the packages in this graph.

Returns the metadata for the given package ID.

Returns the number of packages in this graph.

Returns the number of links in this graph.

Creates a new cache for depends_on queries.

The cache is optional but can speed up some queries.

Returns true if package_a depends (directly or indirectly) on package_b.

In other words, this returns true if package_b is a (possibly transitive) dependency of package_a.

This also returns true if package_a is the same as package_b.

For repeated queries, consider using new_depends_cache to speed up queries.

Returns true if package_a directly depends on package_b.

In other words, this returns true if package_b is a direct dependency of package_a.

This returns false if package_a is the same as package_b.

Returns information about dependency cycles in this graph.

For more information, see the documentation for Cycles.

Helpers for property testing

The methods in this section allow a PackageGraph to be used in property-based testing scenarios.

Currently, proptest 1 is supported if the proptest1 feature is enabled.

This is supported on crate feature proptest1 only.

Returns a Strategy that generates random package IDs from this graph.

Requires the proptest1 feature to be enabled.

Panics

Panics if there are no packages in this PackageGraph.

This is supported on crate feature proptest1 only.

Returns a Strategy that generates random dependency links from this graph.

Requires the proptest1 feature to be enabled.

Panics

Panics if there are no dependency edges in this PackageGraph.

This is supported on crate feature proptest1 only.

Returns a Strategy that generates a random PackageResolver instance from this graph.

Requires the proptest1 feature to be enabled.

This is supported on crate feature proptest1 only.

Returns a Strategy that generates a random CargoOptions from this graph.

Requires the proptest1 feature to be enabled.

Queries

The methods in this section create queries over subsets of this package graph. Use the methods here to analyze transitive dependencies.

Creates a new forward query over the entire workspace.

query_workspace will select all workspace packages and their transitive dependencies. To create a PackageSet with just workspace packages, use resolve_workspace.

Creates a new forward query over the specified workspace packages by path.

Returns an error if any workspace paths were unknown.

Creates a new forward query over the specified workspace packages by name.

This is similar to cargo’s --package option.

Returns an error if any package names were unknown.

Creates a new query that returns transitive dependencies of the given packages in the specified direction.

Returns an error if any package IDs are unknown.

Creates a new query that returns transitive dependencies of the given packages.

Returns an error if any package IDs are unknown.

Creates a new query that returns transitive reverse dependencies of the given packages.

Returns an error if any package IDs are unknown.

Creates a new PackageSet consisting of all members of this package graph.

This is normally the same as query_workspace().resolve(), but can differ if packages have been replaced with [patch] or [replace].

In most situations, query_workspace is preferred. Use resolve_all if you know you need parts of the graph that aren’t accessible from the workspace.

Creates a new, empty PackageSet associated with this package graph.

Creates a new PackageSet consisting of the specified package IDs.

This does not include transitive dependencies. To do so, use the query_ methods.

Returns an error if any package IDs are unknown.

Creates a new PackageSet consisting of all packages in this workspace.

This does not include transitive dependencies. To do so, use query_workspace.

Creates a new PackageSet consisting of the specified workspace packages by path.

This does not include transitive dependencies. To do so, use query_workspace_paths.

Returns an error if any workspace paths are unknown.

Creates a new PackageSet consisting of the specified workspace packages by name.

This does not include transitive dependencies. To do so, use query_workspace_names.

Returns an error if any workspace names are unknown.

Creates a new PackageSet consisting of packages with the given name.

The result is empty if there are no packages with the given name.

This is supported on crate feature summaries only.

Converts this SummaryId to a PackageMetadata.

Returns an error if the summary ID could not be matched.

Requires the summaries feature to be enabled.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Although consuming a MetadataCommand is not required for building a PackageGraph, this impl is provided for convenience.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.