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

A builder for configurating cargo metadata invocation.

Implementations§

Creates a default cargo metadata command, which will look for Cargo.toml in the ancestors of the current directory.

Path to cargo executable. If not set, this will use the the $CARGO environment variable, and if that is not set, will simply be cargo.

Path to Cargo.toml

Current directory of the cargo metadata process.

Output information only about workspace members and don’t fetch dependencies.

Which features to include.

Call this multiple times to specify advanced feature configurations:

MetadataCommand::new()
    .features(CargoOpt::NoDefaultFeatures)
    .features(CargoOpt::SomeFeatures(vec!["feat1".into(), "feat2".into()]))
    .features(CargoOpt::SomeFeatures(vec!["feat3".into()]))
    // ...
Panics

cargo metadata rejects multiple --no-default-features flags. Similarly, the features() method panics when specifying multiple CargoOpt::NoDefaultFeatures:

MetadataCommand::new()
    .features(CargoOpt::NoDefaultFeatures)
    .features(CargoOpt::NoDefaultFeatures) // <-- panic!
    // ...

The method also panics for multiple CargoOpt::AllFeatures arguments:

MetadataCommand::new()
    .features(CargoOpt::AllFeatures)
    .features(CargoOpt::AllFeatures) // <-- panic!
    // ...

Arbitrary command line flags to pass to cargo. These will be added to the end of the command line invocation.

Arbitrary environment variables to set when running cargo. These will be merged into the calling environment, overriding any which clash.

Some examples of when you may want to use this:

  1. Setting cargo config values without needing a .cargo/config.toml file, e.g. to set CARGO_NET_GIT_FETCH_WITH_CLI=true
  2. To specify a custom path to RUSTC if your rust toolchain components aren’t laid out in the way cargo expects by default.
MetadataCommand::new()
    .env("CARGO_NET_GIT_FETCH_WITH_CLI", "true")
    .env("RUSTC", "/path/to/rustc")
    // ...

Set whether to show stderr

Builds a command for cargo metadata. This is the first part of the work of exec.

Parses cargo metadata output. data must have been produced by a command built with cargo_command.

Runs configured cargo metadata and returns parsed Metadata.

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
Returns the “default value” for a type. Read more

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 resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
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.