pub struct MetadataCommand { /* private fields */ }Expand description
A builder for configurating cargo metadata invocation.
Implementations§
Source§impl MetadataCommand
impl MetadataCommand
Sourcepub fn new() -> MetadataCommand
pub fn new() -> MetadataCommand
Creates a default cargo metadata command, which will look for
Cargo.toml in the ancestors of the current directory.
Sourcepub fn cargo_path(&mut self, path: impl Into<PathBuf>) -> &mut MetadataCommand
pub fn cargo_path(&mut self, path: impl Into<PathBuf>) -> &mut MetadataCommand
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.
Sourcepub fn manifest_path(
&mut self,
path: impl Into<PathBuf>,
) -> &mut MetadataCommand
pub fn manifest_path( &mut self, path: impl Into<PathBuf>, ) -> &mut MetadataCommand
Path to Cargo.toml
Sourcepub fn current_dir(&mut self, path: impl Into<PathBuf>) -> &mut MetadataCommand
pub fn current_dir(&mut self, path: impl Into<PathBuf>) -> &mut MetadataCommand
Current directory of the cargo metadata process.
Sourcepub fn no_deps(&mut self) -> &mut MetadataCommand
pub fn no_deps(&mut self) -> &mut MetadataCommand
Output information only about workspace members and don’t fetch dependencies.
Sourcepub fn features(&mut self, features: CargoOpt) -> &mut MetadataCommand
pub fn features(&mut self, features: CargoOpt) -> &mut MetadataCommand
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!
// ...Sourcepub fn other_options(
&mut self,
options: impl Into<Vec<String>>,
) -> &mut MetadataCommand
pub fn other_options( &mut self, options: impl Into<Vec<String>>, ) -> &mut MetadataCommand
Arbitrary command line flags to pass to cargo. These will be added
to the end of the command line invocation.
Sourcepub fn env<K: Into<OsString>, V: Into<OsString>>(
&mut self,
key: K,
val: V,
) -> &mut MetadataCommand
pub fn env<K: Into<OsString>, V: Into<OsString>>( &mut self, key: K, val: V, ) -> &mut MetadataCommand
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:
- Setting cargo config values without needing a .cargo/config.toml file, e.g. to set
CARGO_NET_GIT_FETCH_WITH_CLI=true - 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")
// ...Sourcepub fn verbose(&mut self, verbose: bool) -> &mut MetadataCommand
pub fn verbose(&mut self, verbose: bool) -> &mut MetadataCommand
Set whether to show stderr
Sourcepub fn cargo_command(&self) -> Command
pub fn cargo_command(&self) -> Command
Builds a command for cargo metadata. This is the first
part of the work of exec.
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 more