|
1 | 1 | // SPDX-License-Identifier: MPL-2.0
|
2 | 2 |
|
3 |
| -//! PubGrub version solving algorithm. |
4 |
| -//! |
5 |
| -//! It consists in efficiently finding a set of packages and versions |
6 |
| -//! that satisfy all the constraints of a given project dependencies. |
7 |
| -//! In addition, when that is not possible, |
8 |
| -//! PubGrub tries to provide a very human-readable and clear |
9 |
| -//! explanation as to why that failed. |
10 |
| -//! Below is an example of explanation present in |
11 |
| -//! the introductory blog post about PubGrub |
12 |
| -//! |
13 |
| -//! ```txt |
14 |
| -//! Because dropdown >=2.0.0 depends on icons >=2.0.0 and |
15 |
| -//! root depends on icons <2.0.0, dropdown >=2.0.0 is forbidden. |
16 |
| -//! |
17 |
| -//! And because menu >=1.1.0 depends on dropdown >=2.0.0, |
18 |
| -//! menu >=1.1.0 is forbidden. |
19 |
| -//! |
20 |
| -//! And because menu <1.1.0 depends on dropdown >=1.0.0 <2.0.0 |
21 |
| -//! which depends on intl <4.0.0, every version of menu |
22 |
| -//! requires intl <4.0.0. |
23 |
| -//! |
24 |
| -//! So, because root depends on both menu >=1.0.0 and intl >=5.0.0, |
25 |
| -//! version solving failed. |
26 |
| -//! ``` |
27 |
| -//! |
28 |
| -//! The algorithm is generic and works for any type of dependency system |
29 |
| -//! as long as packages (P) and versions (V) implement |
30 |
| -//! the [Package] and Version traits. |
31 |
| -//! [Package] is strictly equivalent and automatically generated |
32 |
| -//! for any type that implement [Clone] + [Eq] + [Hash] + [Debug] + [Display]. |
33 |
| -//! |
34 |
| -//! ## API |
35 |
| -//! |
36 |
| -//! ``` |
37 |
| -//! # use std::convert::Infallible; |
38 |
| -//! # use pubgrub::{resolve, OfflineDependencyProvider, PubGrubError, Ranges}; |
39 |
| -//! # |
40 |
| -//! # type NumVS = Ranges<u32>; |
41 |
| -//! # |
42 |
| -//! # fn try_main() -> Result<(), PubGrubError<OfflineDependencyProvider<&'static str, NumVS>>> { |
43 |
| -//! # let dependency_provider = OfflineDependencyProvider::<&str, NumVS>::new(); |
44 |
| -//! # let package = "root"; |
45 |
| -//! # let version = 1u32; |
46 |
| -//! let solution = resolve(&dependency_provider, package, version)?; |
47 |
| -//! # Ok(()) |
48 |
| -//! # } |
49 |
| -//! # fn main() { |
50 |
| -//! # assert!(matches!(try_main(), Err(PubGrubError::NoSolution(_)))); |
51 |
| -//! # } |
52 |
| -//! ``` |
53 |
| -//! |
54 |
| -//! Where `dependency_provider` supplies the list of available packages and versions, |
55 |
| -//! as well as the dependencies of every available package |
56 |
| -//! by implementing the [DependencyProvider] trait. |
57 |
| -//! The call to [resolve] for a given package at a given version |
58 |
| -//! will compute the set of packages and versions needed |
59 |
| -//! to satisfy the dependencies of that package and version pair. |
60 |
| -//! If there is no solution, the reason will be provided as clear as possible. |
61 |
| -
|
62 | 3 | use std::collections::BTreeSet as Set;
|
63 | 4 | use std::error::Error;
|
64 | 5 | use std::fmt::{Debug, Display};
|
@@ -107,8 +48,62 @@ impl PackageResolutionStatistics {
|
107 | 48 | }
|
108 | 49 | }
|
109 | 50 |
|
110 |
| -/// Main function of the library. |
111 | 51 | /// Finds a set of packages satisfying dependency bounds for a given package + version pair.
|
| 52 | +/// |
| 53 | +/// It consists in efficiently finding a set of packages and versions |
| 54 | +/// that satisfy all the constraints of a given project dependencies. |
| 55 | +/// In addition, when that is not possible, |
| 56 | +/// PubGrub tries to provide a very human-readable and clear |
| 57 | +/// explanation as to why that failed. |
| 58 | +/// Below is an example of explanation present in |
| 59 | +/// the introductory blog post about PubGrub |
| 60 | +/// (Although this crate is not yet capable of building formatting quite this nice.) |
| 61 | +/// |
| 62 | +/// ```txt |
| 63 | +/// Because dropdown >=2.0.0 depends on icons >=2.0.0 and |
| 64 | +/// root depends on icons <2.0.0, dropdown >=2.0.0 is forbidden. |
| 65 | +/// |
| 66 | +/// And because menu >=1.1.0 depends on dropdown >=2.0.0, |
| 67 | +/// menu >=1.1.0 is forbidden. |
| 68 | +/// |
| 69 | +/// And because menu <1.1.0 depends on dropdown >=1.0.0 <2.0.0 |
| 70 | +/// which depends on intl <4.0.0, every version of menu |
| 71 | +/// requires intl <4.0.0. |
| 72 | +/// |
| 73 | +/// So, because root depends on both menu >=1.0.0 and intl >=5.0.0, |
| 74 | +/// version solving failed. |
| 75 | +/// ``` |
| 76 | +/// |
| 77 | +/// Is generic over an implementation of [DependencyProvider] which represents where the dependency constraints come from. |
| 78 | +/// The associated types on the DependencyProvider allow flexibility for the representation of |
| 79 | +/// package names, version requirements, version numbers, and other things. |
| 80 | +/// See its documentation for more details. |
| 81 | +/// For simple cases [OfflineDependencyProvider](crate::OfflineDependencyProvider) may be sufficient. |
| 82 | +/// |
| 83 | +/// ## API |
| 84 | +/// |
| 85 | +/// ``` |
| 86 | +/// # use std::convert::Infallible; |
| 87 | +/// # use pubgrub::{resolve, OfflineDependencyProvider, PubGrubError, Ranges}; |
| 88 | +/// # |
| 89 | +/// # type NumVS = Ranges<u32>; |
| 90 | +/// # |
| 91 | +/// # fn try_main() -> Result<(), PubGrubError<OfflineDependencyProvider<&'static str, NumVS>>> { |
| 92 | +/// # let dependency_provider = OfflineDependencyProvider::<&str, NumVS>::new(); |
| 93 | +/// # let package = "root"; |
| 94 | +/// # let version = 1u32; |
| 95 | +/// let solution = resolve(&dependency_provider, package, version)?; |
| 96 | +/// # Ok(()) |
| 97 | +/// # } |
| 98 | +/// # fn main() { |
| 99 | +/// # assert!(matches!(try_main(), Err(PubGrubError::NoSolution(_)))); |
| 100 | +/// # } |
| 101 | +/// ``` |
| 102 | +/// |
| 103 | +/// The call to [resolve] for a given package at a given version |
| 104 | +/// will compute the set of packages and versions needed |
| 105 | +/// to satisfy the dependencies of that package and version pair. |
| 106 | +/// If there is no solution, the reason will be provided as clear as possible. |
112 | 107 | #[cold]
|
113 | 108 | pub fn resolve<DP: DependencyProvider>(
|
114 | 109 | dependency_provider: &DP,
|
|
0 commit comments