Crate cargo_metadata
source ·Expand description
Structured access to the output of cargo metadata
Usually used from within a cargo-*
executable
Examples
With std::env::args()
:
let mut args = std::env::args().skip_while(|val| !val.starts_with("--manifest-path"));
let manifest_path = match args.next() {
Some(ref p) if p == "--manifest-path" => args.next(),
Some(p) => Some(p.trim_left_matches("--manifest-path=").to_string()),
None => None,
};
let _metadata = cargo_metadata::metadata(manifest_path.as_ref().map(Path::new)).unwrap();
With docopt
:
const USAGE: &str = "
Cargo metadata test function
Usage:
cargo_metadata [--manifest-path PATH]
";
#[derive(Debug, Deserialize)]
struct Args {
arg_manifest_path: Option<String>,
}
let args: Args = Docopt::new(USAGE)
.and_then(|d| d.deserialize())
.unwrap_or_else(|e| e.exit());
let _metadata =
cargo_metadata::metadata(args.arg_manifest_path.as_ref().map(Path::new)).unwrap();
With clap
:
let matches = clap::App::new("myapp")
.arg(
clap::Arg::with_name("manifest-path")
.long("manifest-path")
.value_name("PATH")
.takes_value(true),
)
.get_matches();
let _metadata =
cargo_metadata::metadata(matches.value_of("manifest-path").map(Path::new)).unwrap();
Pass features flags
let manifest_path = Path::new("./Cargo.toml");
let features = cargo_metadata::CargoOpt::AllFeatures;
let _metadata =
cargo_metadata::metadata_run(Some(manifest_path), false, Some(features)).unwrap();
Structs
A dependency of the main crate
The Error type.
Starting point for metadata returned by
cargo metadata
A node in a dependencies graph
A crate
A dependency graph
A single target (lib, bin, example, …) provided by a crate
A workspace member. This is basically identical to
cargo::core::package_id::PackageId
, except
that this does not use Arc
internally.Enums
Cargo features flags
Dependencies can come in three kinds
The kind of an error.
Functions
Obtain metadata only about the root package and don’t fetch dependencies
Obtain metadata only about the root package and dependencies
The main entry point to obtaining metadata
Type Definitions
Convenient wrapper around
std::Result
.