Name Description Size Coverage
dependency.rs This module contains `Dependency` and the types/functions it uses for deserialization. 2814 -
diagnostic.rs This module contains `Diagnostic` and the types/functions it uses for deserialization. 6014 -
errors.rs 2200 -
lib.rs Structured access to the output of `cargo metadata` and `cargo --message-format=json`. Usually used from within a `cargo-*` executable See the [cargo book](https://doc.rust-lang.org/cargo/index.html) for details on cargo itself. ## Examples Get the current crate's metadata without default features but with all dependency information. ```rust # use std::path::Path; # use cargo_metadata::{MetadataCommand, CargoOpt}; let _metadata = MetadataCommand::new().exec().unwrap(); ``` If you have a program that takes `--manifest-path` as an argument, you can forward that to [MetadataCommand]: ```rust # use cargo_metadata::MetadataCommand; # use std::path::Path; let mut args = std::env::args().skip_while(|val| !val.starts_with("--manifest-path")); let mut cmd = MetadataCommand::new(); let manifest_path = match args.next() { Some(ref p) if p == "--manifest-path" => { cmd.manifest_path(args.next().unwrap()); } Some(p) => { cmd.manifest_path(p.trim_start_matches("--manifest-path=")); } None => {} }; let _metadata = cmd.exec().unwrap(); ``` Pass features flags, e.g. `--all-features`. ```rust # use std::path::Path; # use cargo_metadata::{MetadataCommand, CargoOpt}; let _metadata = MetadataCommand::new() .manifest_path("./Cargo.toml") .features(CargoOpt::AllFeatures) .exec() .unwrap(); ``` Parse message-format output produced by other cargo commands. It is recommended to use crates like `escargot` to produce the [Command]. ``` # use std::process::{Stdio, Command}; # use cargo_metadata::Message; let mut command = Command::new("cargo") .args(&["build", "--message-format=json-render-diagnostics"]) .stdout(Stdio::piped()) .spawn() .unwrap(); let reader = std::io::BufReader::new(command.stdout.take().unwrap()); for message in cargo_metadata::Message::parse_stream(reader) { match message.unwrap() { Message::CompilerMessage(msg) => { println!("{:?}", msg); }, Message::CompilerArtifact(artifact) => { println!("{:?}", artifact); }, Message::BuildScriptExecuted(script) => { println!("{:?}", script); }, Message::BuildFinished(finished) => { println!("{:?}", finished); }, _ => () // Unknown message } } let output = command.wait().expect("Couldn't get cargo's exit status"); ``` 46953 -
libtest.rs Parses output of [libtest](https://github.com/rust-lang/rust/blob/master/library/test/src/formatters/json.rs). Since this module parses output in an unstable format, all structs in this module may change at any time, and are exempt from semver guarantees. 6492 -
messages.rs 10453 -