Skip to content

Commit 96384b2

Browse files
committed
Split version ranges into their own crate
1 parent fe65959 commit 96384b2

File tree

10 files changed

+236
-207
lines changed

10 files changed

+236
-207
lines changed

.github/workflows/ci.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ jobs:
1616
steps:
1717
- uses: actions/checkout@v4
1818
- uses: dtolnay/rust-toolchain@stable
19-
- run: cargo build --verbose
20-
- run: cargo test --features=serde --verbose
19+
- run: cargo build --verbose --workspace
20+
- run: cargo test --features serde --workspace --verbose
2121

2222
clippy:
2323
name: No warnings from Clippy
@@ -30,7 +30,7 @@ jobs:
3030
- name: Check Clippy lints
3131
env:
3232
RUSTFLAGS: -D warnings
33-
run: cargo clippy
33+
run: cargo clippy --workspace
3434

3535
check_formatting:
3636
name: Source code is formatted
@@ -40,7 +40,7 @@ jobs:
4040
- uses: dtolnay/rust-toolchain@stable
4141
with:
4242
components: rustfmt
43-
- run: cargo fmt --all -- --check
43+
- run: cargo fmt --workspace -- --check
4444

4545
check_documentation:
4646
name: Documentation builds successfully
@@ -51,4 +51,4 @@ jobs:
5151
- name: Check documentation
5252
env:
5353
RUSTDOCFLAGS: -D warnings
54-
run: cargo doc --no-deps --document-private-items
54+
run: cargo doc --workspace --no-deps --document-private-items

Cargo.lock

Lines changed: 18 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# SPDX-License-Identifier: MPL-2.0
22

3+
[workspace]
4+
members = ["version-range"]
5+
36
[package]
47
name = "pubgrub"
58
version = "0.2.1"
@@ -21,18 +24,22 @@ include = ["Cargo.toml", "LICENSE", "README.md", "src/**", "tests/**", "examples
2124

2225
[dependencies]
2326
indexmap = "2.5.0"
27+
log = "0.4.22" # for debug logs in tests
2428
priority-queue = "2.1.0"
25-
thiserror = "1.0"
2629
rustc-hash = ">=1.0.0, <3.0.0"
2730
serde = { version = "1.0", features = ["derive"], optional = true }
28-
log = "0.4.22" # for debug logs in tests
31+
thiserror = "1.0"
32+
version-range = { version = "0.1.0", path = "version-range" }
2933

3034
[dev-dependencies]
3135
proptest = "1.5.0"
32-
ron = "=0.9.0-alpha.0"
3336
varisat = "0.2.2"
3437
criterion = "0.5"
3538
env_logger = "0.11.5"
39+
version-range = { version = "0.1.0", path = "version-range", features = ["proptest"] }
40+
41+
[features]
42+
serde = ["dep:serde", "version-range/serde"]
3643

3744
[[bench]]
3845
name = "large_case"

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,6 @@
212212

213213
mod error;
214214
mod package;
215-
mod range;
216215
mod report;
217216
mod solver;
218217
mod term;
@@ -222,7 +221,6 @@ mod version_set;
222221

223222
pub use error::{NoSolutionError, PubGrubError};
224223
pub use package::Package;
225-
pub use range::Range;
226224
pub use report::{
227225
DefaultStringReportFormatter, DefaultStringReporter, DerivationTree, Derived, External,
228226
ReportFormatter, Reporter,
@@ -231,6 +229,7 @@ pub use solver::{resolve, Dependencies, DependencyProvider, OfflineDependencyPro
231229
pub use term::Term;
232230
pub use type_aliases::{DependencyConstraints, Map, SelectedDependencies, Set};
233231
pub use version::{SemanticVersion, VersionParseError};
232+
pub use version_range::Range;
234233
pub use version_set::VersionSet;
235234

236235
mod internal;

src/solver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ pub trait DependencyProvider {
199199
/// How this provider stores the version requirements for the packages.
200200
/// The requirements must be able to process the same kind of version as this dependency provider.
201201
///
202-
/// A common choice is [`Range`][crate::range::Range].
202+
/// A common choice is [`Range`][version_range::Range].
203203
type VS: VersionSet<V = Self::V>;
204204

205205
/// Type for custom incompatibilities.

src/term.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -220,15 +220,14 @@ impl<VS: VersionSet + Display> Display for Term<VS> {
220220

221221
#[cfg(test)]
222222
pub mod tests {
223-
use proptest::prelude::*;
224-
225223
use super::*;
226-
use crate::Range;
224+
use proptest::prelude::*;
225+
use version_range::Range;
227226

228227
pub fn strategy() -> impl Strategy<Value = Term<Range<u32>>> {
229228
prop_oneof![
230-
crate::range::tests::strategy().prop_map(Term::Positive),
231-
crate::range::tests::strategy().prop_map(Term::Negative),
229+
version_range::proptest_strategy().prop_map(Term::Negative),
230+
version_range::proptest_strategy().prop_map(Term::Positive),
232231
]
233232
}
234233
proptest! {

src/version_set.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@
2020
2121
use std::fmt::{Debug, Display};
2222

23+
use crate::Range;
24+
2325
/// Trait describing sets of versions.
2426
pub trait VersionSet: Debug + Display + Clone + Eq {
2527
/// Version type associated with the sets manipulated.
@@ -68,3 +70,43 @@ pub trait VersionSet: Debug + Display + Clone + Eq {
6870
self == &self.intersection(other)
6971
}
7072
}
73+
74+
impl<T: Debug + Display + Clone + Eq + Ord> VersionSet for Range<T> {
75+
type V = T;
76+
77+
fn empty() -> Self {
78+
Range::empty()
79+
}
80+
81+
fn singleton(v: Self::V) -> Self {
82+
Range::singleton(v)
83+
}
84+
85+
fn complement(&self) -> Self {
86+
Range::complement(self)
87+
}
88+
89+
fn intersection(&self, other: &Self) -> Self {
90+
Range::intersection(self, other)
91+
}
92+
93+
fn contains(&self, v: &Self::V) -> bool {
94+
Range::contains(self, v)
95+
}
96+
97+
fn full() -> Self {
98+
Range::full()
99+
}
100+
101+
fn union(&self, other: &Self) -> Self {
102+
Range::union(self, other)
103+
}
104+
105+
fn is_disjoint(&self, other: &Self) -> bool {
106+
Range::is_disjoint(self, other)
107+
}
108+
109+
fn subset_of(&self, other: &Self) -> bool {
110+
Range::subset_of(self, other)
111+
}
112+
}

version-range/Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

version-range/Cargo.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
[package]
2+
name = "version-range"
3+
version = "0.1.0"
4+
edition = "2021"
5+
keywords = ["version", "pubgrub", "selector", "ranges"]
6+
7+
[dependencies]
8+
proptest = { version = "1.5.0", optional = true }
9+
serde = { version = "1.0.210", features = ["derive"], optional = true }
10+
smallvec = { version = "1.13.2" }
11+
12+
[features]
13+
serde = ["dep:serde", "smallvec/serde"]
14+
15+
[dev-dependencies]
16+
proptest = "1.5.0"
17+
ron = "=0.9.0-alpha.0"

0 commit comments

Comments
 (0)