retworkx_core/lib.rs
1// Licensed under the Apache License, Version 2.0 (the "License"); you may
2// not use this file except in compliance with the License. You may obtain
3// a copy of the License at
4//
5// http://www.apache.org/licenses/LICENSE-2.0
6//
7// Unless required by applicable law or agreed to in writing, software
8// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
9// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
10// License for the specific language governing permissions and limitations
11// under the License.
12
13//! # retworkx-core
14//!
15//! retworkx-core is a graph algorithm crate built on top of [`petgraph`]. It offers
16//! a set of functions that are used in the larger retworkx project but
17//! implemented in a generic manner for use by downstream rust projects.
18//!
19//! ## Usage
20//!
21//! First add this crate to your `Cargo.toml`:
22//!
23//! ```toml
24//! [dependencies]
25//! retworkx-core = "0.11"
26//! ```
27//!
28//! Then in your code, it may be used something like this:
29//!
30//! ```rust
31//! use retworkx_core::petgraph;
32//! use retworkx_core::centrality::betweenness_centrality;
33//!
34//! let g = petgraph::graph::UnGraph::<i32, ()>::from_edges(&[
35//! (1, 2), (2, 3), (3, 4), (1, 4)
36//! ]);
37//! // Calculate the betweeness centrality
38//! let output = betweenness_centrality(&g, false, false, 200);
39//! assert_eq!(
40//! vec![Some(0.0), Some(0.5), Some(0.5), Some(0.5), Some(0.5)],
41//! output
42//! );
43//! ```
44//!
45//! ## Algorithm Modules
46//!
47//! The crate is organized into
48//!
49//! * [`centrality`](./centrality/index.html)
50//! * [`connectivity`](./connectivity/index.html)
51//! * [`max_weight_matching`](./max_weight_matching/index.html)
52//! * [`shortest_path`](./shortest_path/index.html)
53//!
54//! ## Release Notes
55//!
56//! The release notes for retworkx-core are included as part of the retworkx
57//! documentation which is hosted at:
58//!
59//! <https://qiskit.org/documentation/retworkx/release_notes.html>
60
61use std::convert::Infallible;
62
63/// A convenient type alias that by default assumes no error can happen.
64///
65/// It can be used to avoid type annotations when the function you want
66/// to use needs a callback that returns [`Result`] but in your case no
67/// error can happen.
68pub type Result<T, E = Infallible> = core::result::Result<T, E>;
69
70/// Module for centrality algorithms
71pub mod centrality;
72pub mod connectivity;
73/// Module for maximum weight matching algorithmss
74pub mod max_weight_matching;
75pub mod shortest_path;
76pub mod traversal;
77// These modules define additional data structures
78pub mod dictmap;
79pub mod distancemap;
80mod min_scored;
81
82// re-export petgraph so there is a consistent version available to users and
83// then only need to require retworkx-core in their dependencies
84pub use petgraph;