Crate cargo_metadata [] [src]

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();

Structs

Dependency

A dependency of the main crate

Error

The Error type.

Metadata

Starting point for metadata returned by cargo metadata

Node

A node in a dependencies graph

Package

A crate

Resolve

A dependency graph

Target

A single target (lib, bin, example, ...) provided by a crate

Enums

DependencyKind

Dependencies can come in three kinds

ErrorKind

The kind of an error.

Functions

metadata

Obtain metadata only about the root package and don't fetch dependencies

metadata_deps

The main entry point to obtaining metadata

Type Definitions

Result

Convenient wrapper around std::Result.