use std::collections::HashMap; use std::process::Command; use std::str::{from_utf8, Utf8Error}; use std::io; use rustc_serialize::json; #[derive(RustcDecodable, Debug)] pub struct Metadata { pub packages: Vec, resolve: Option<()>, pub version: usize, } #[derive(RustcDecodable, Debug)] pub struct Package { pub name: String, pub version: String, id: String, source: Option, pub dependencies: Vec, pub targets: Vec, features: HashMap>, manifest_path: String, } #[derive(RustcDecodable, Debug)] pub struct Dependency { pub name: String, source: Option, pub req: String, kind: Option, optional: bool, uses_default_features: bool, features: Vec, target: Option<()>, } #[derive(RustcDecodable, Debug)] pub struct Target { pub name: String, pub kind: Vec, src_path: String, } #[derive(Debug)] pub enum Error { Io(io::Error), Utf8(Utf8Error), Json(json::DecoderError), } impl From for Error { fn from(err: io::Error) -> Self { Error::Io(err) } } impl From for Error { fn from(err: Utf8Error) -> Self { Error::Utf8(err) } } impl From for Error { fn from(err: json::DecoderError) -> Self { Error::Json(err) } } pub fn metadata() -> Result { let output = Command::new("cargo").args(&["metadata", "--no-deps"]).output()?; let stdout = from_utf8(&output.stdout)?; Ok(json::decode(stdout)?) }