pub struct MetadataCommand { /* private fields */ }
Expand description
A builder for configuring cargo metadata
invocations.
This is the most common entry point for constructing a PackageGraph
.
§Examples
Build a PackageGraph
for the Cargo workspace in the current directory:
use guppy::MetadataCommand;
use guppy::graph::PackageGraph;
let mut cmd = MetadataCommand::new();
let package_graph = PackageGraph::from_command(&mut cmd);
Implementations§
Source§impl MetadataCommand
impl MetadataCommand
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a default cargo metadata
command builder.
By default, this will look for Cargo.toml
in the ancestors of this process’s current
directory.
Sourcepub fn cargo_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
pub fn cargo_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
Sets the path to the cargo
executable.
If unset, this will use the $CARGO
environment variable, or else cargo
from $PATH
.
Sourcepub fn manifest_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
pub fn manifest_path(&mut self, path: impl Into<PathBuf>) -> &mut Self
Sets the path to Cargo.toml
.
By default, this will look for Cargo.toml
in the ancestors of the current directory. Note
that this doesn’t need to be the root Cargo.toml
in a workspace – any member of the
workspace is fine.
Sourcepub fn current_dir(&mut self, path: impl Into<PathBuf>) -> &mut Self
pub fn current_dir(&mut self, path: impl Into<PathBuf>) -> &mut Self
Sets the current directory of the cargo metadata
process.
By default, the current directory will be inherited from this process.
Sourcepub fn no_deps(&mut self) -> &mut Self
pub fn no_deps(&mut self) -> &mut Self
Output information only about the workspace and do not fetch dependencies.
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
Constructing a graph with this option can be several times faster than the default.
Sourcepub fn other_options(
&mut self,
options: impl IntoIterator<Item = impl Into<String>>,
) -> &mut Self
pub fn other_options( &mut self, options: impl IntoIterator<Item = impl Into<String>>, ) -> &mut Self
Arbitrary flags to pass to cargo metadata
. These will be added to the end of the
command invocation.
Note that guppy
internally:
- uses
--format-version 1
as its metadata format. - passes in
--all-features
, so thatguppy
has a full view of the dependency graph.
Attempting to override either of those options may lead to unexpected results.
Sourcepub fn cargo_command(&self) -> Command
pub fn cargo_command(&self) -> Command
Sourcepub fn exec(&self) -> Result<CargoMetadata, Error>
pub fn exec(&self) -> Result<CargoMetadata, Error>
Runs the configured cargo metadata
and returns a deserialized CargoMetadata
.
Sourcepub fn build_graph(&self) -> Result<PackageGraph, Error>
pub fn build_graph(&self) -> Result<PackageGraph, Error>
Runs the configured cargo metadata
and returns a parsed PackageGraph
.
Trait Implementations§
Source§impl Clone for MetadataCommand
impl Clone for MetadataCommand
Source§fn clone(&self) -> MetadataCommand
fn clone(&self) -> MetadataCommand
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for MetadataCommand
impl Debug for MetadataCommand
Source§impl Default for MetadataCommand
impl Default for MetadataCommand
Source§fn default() -> MetadataCommand
fn default() -> MetadataCommand
Source§impl<'a> TryFrom<&'a MetadataCommand> for PackageGraph
impl<'a> TryFrom<&'a MetadataCommand> for PackageGraph
Source§impl TryFrom<MetadataCommand> for PackageGraph
impl TryFrom<MetadataCommand> for PackageGraph
Although consuming a MetadataCommand
is not required for building a PackageGraph
, this impl
is provided for convenience.
Auto Trait Implementations§
impl Freeze for MetadataCommand
impl RefUnwindSafe for MetadataCommand
impl Send for MetadataCommand
impl Sync for MetadataCommand
impl Unpin for MetadataCommand
impl UnwindSafe for MetadataCommand
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)