Skip to main content

use_graph/
lib.rs

1#![forbid(unsafe_code)]
2//! Thin facade for the `use-graph` workspace.
3//!
4//! The crate reexports the focused graph crates directly so consumers can opt
5//! into one dependency while still using the smaller APIs.
6//!
7//! # Examples
8//!
9//! ```rust
10//! use use_graph::*;
11//!
12//! let adjacency = build_directed_adjacency(4, &[(0, 1), (1, 2), (0, 3)]).unwrap();
13//! let path = shortest_path_unweighted(&adjacency, 0, 2).unwrap().unwrap();
14//! let edge = WeightedEdge::new(0, 1, 1.5).unwrap();
15//!
16//! assert_eq!(path.nodes(), &[0, 1, 2]);
17//! assert_eq!(path_weight(&[edge]).unwrap(), 1.5);
18//! assert_eq!(max_degree(&adjacency), Some(2));
19//! ```
20
21pub use use_adjacency;
22pub use use_adjacency::*;
23pub use use_edge;
24pub use use_edge::*;
25pub use use_graph_metrics;
26pub use use_graph_metrics::*;
27pub use use_graph_path;
28pub use use_graph_path::*;
29pub use use_graph_traversal;
30pub use use_graph_traversal::*;
31pub use use_node;
32pub use use_node::*;
33pub use use_weighted_graph;
34pub use use_weighted_graph::*;
35
36#[cfg(test)]
37mod tests {
38    use super::{
39        build_directed_adjacency, max_degree, node_ids, path_weight, shortest_path_unweighted,
40        WeightedEdge,
41    };
42
43    #[test]
44    fn facade_reexports_workspace_apis() {
45        let nodes = node_ids(4);
46        assert_eq!(nodes.len(), 4);
47
48        let adjacency = build_directed_adjacency(4, &[(0, 1), (1, 2), (0, 3)]).unwrap();
49        let path = shortest_path_unweighted(&adjacency, 0, 2).unwrap().unwrap();
50        assert_eq!(path.nodes(), &[0, 1, 2]);
51
52        let edge = WeightedEdge::new(0, 1, 1.5).unwrap();
53        assert_eq!(path_weight(&[edge]).unwrap(), 1.5);
54        assert_eq!(max_degree(&adjacency), Some(2));
55    }
56}