1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
// Copyright (c) The cargo-guppy Contributors // SPDX-License-Identifier: MIT OR Apache-2.0 //! Track and query Cargo dependency graphs. //! //! `guppy` provides a Rust interface to run queries over Cargo dependency graphs. `guppy` parses //! the output of [`cargo metadata`](https://doc.rust-lang.org/cargo/commands/cargo-metadata.html), //! then presents a graph interface over it. //! //! # Usage //! //! Add the following to `Cargo.toml`: //! //! ```toml //! [dependencies] //! guppy = "0.1" //! ``` //! //! # Examples //! //! Print out all direct dependencies of a package: //! //! ``` //! use guppy::graph::PackageGraph; //! use guppy::PackageId; //! //! // `guppy` accepts `cargo metadata` JSON output. Use a pre-existing fixture for these examples. //! let fixture = include_str!("../fixtures/metadata1.json"); //! let package_graph = PackageGraph::from_json(fixture).unwrap(); //! //! // `guppy` provides several ways to get hold of package IDs. Use a pre-defined one for this //! // example. //! let package_id = PackageId { repr: "testcrate 0.1.0 (path+file:///fakepath/testcrate)".into() }; //! // dep_links returns all direct dependencies of a package, and it returns `None` if the package //! // ID isn't recognized. //! for link in package_graph.dep_links(&package_id).unwrap() { //! // A dependency link contains `from`, `to` and `edge`. The edge has information about e.g. //! // whether this is a build dependency. //! println!("direct dependency: {}", link.to.id()); //! } //! ``` //! //! For more examples, see //! [the `examples` directory](https://github.com/calibra/cargo-guppy/tree/master/guppy/examples). #![warn(missing_docs)] // config isn't used at the moment so hide it from docs. #[doc(hidden)] pub mod config; pub mod errors; pub mod graph; pub(crate) mod petgraph_support; #[cfg(test)] mod unit_tests; pub use errors::Error; // Public re-exports for upstream crates used in APIs. The no_inline ensures that they show up as // re-exports in documentation. #[doc(no_inline)] pub use cargo_metadata::{Metadata, MetadataCommand, PackageId}; #[doc(no_inline)] pub use semver::Version; #[doc(no_inline)] pub use serde_json::Value as JsonValue;