Skip to content

Commit 4099a2e

Browse files
authored
Add version ranges readme (#266)
* Add version ranges readme Mostly copied and edited from the crate description. The image came out underwhelming, but i want to include that visualization as a number line, it's my most used tool when interacting with ranges. * Better image * Shorten arrows
1 parent 216f3fd commit 4099a2e

File tree

5 files changed

+97
-9
lines changed

5 files changed

+97
-9
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

version-ranges/Cargo.lock

Lines changed: 0 additions & 7 deletions
This file was deleted.

version-ranges/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
[package]
22
name = "version-ranges"
3-
version = "0.1.0"
3+
version = "0.1.1"
44
description = "Performance-optimized type for generic version ranges and operations on them."
55
edition = "2021"
66
repository = "https://github.com/pubgrub-rs/pubgrub"
77
license = "MPL-2.0"
88
keywords = ["version", "pubgrub", "selector", "ranges"]
9+
include = ["ranges.png", "src"]
910

1011
[dependencies]
1112
proptest = { version = "1.5.0", optional = true }

version-ranges/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Ranges
2+
3+
[![crates.io](https://img.shields.io/crates/v/version-ranges.svg?logo=rust)](https://crates.io/crates/version-ranges)
4+
[![docs.rs](https://img.shields.io/badge/docs.rs-version-ranges)](https://docs.rs/version-ranges)
5+
6+
This crate contains a performance-optimized type for generic version ranges and operations on them.
7+
8+
`Ranges` can represent version selectors such as `(>=1.5.1, <2) OR (==3.1) OR (>4)`. Internally, it is an ordered list
9+
of contiguous intervals (segments) with inclusive, exclusive or open-ended ends, similar to a
10+
`Vec<(Bound<T>, Bound<T>)>`.
11+
12+
You can construct a basic range from one of the following build blocks. All other ranges are concatenation, union, and
13+
complement of these basic ranges.
14+
15+
- `Ranges::empty()`: No version
16+
- `Ranges::full()`: All versions
17+
- `Ranges::singleton(v)`: Only the version v exactly
18+
- `Ranges::higher_than(v)`: All versions `v <= versions`
19+
- `Ranges::strictly_higher_than(v)`: All versions `v < versions`
20+
- `Ranges::lower_than(v)`: All versions `versions <= v`
21+
- `Ranges::strictly_lower_than(v)`: All versions `versions < v`
22+
- `Ranges::between(v1, v2)`: All versions `v1 <= versions < v2`
23+
24+
The optimized operations include `complement`, `contains`, `contains_many`, `intersection`, `is_disjoint`,
25+
`subset_of` and `union`.
26+
27+
`Ranges` is generic over any type that implements `Ord` + `Clone` and can represent all kinds of slices with ordered
28+
coordinates, not just version ranges. While built as a performance-critical piece
29+
of [pubgrub](https://github.com/pubgrub-rs/pubgrub), it can be adopted for other domains, too.
30+
31+
![A number line and a sample range on it](number-line-ranges.svg)
32+
33+
You can imagine a `Ranges` as slices over a number line.
34+
35+
Note that there are limitations to the equality implementation: Given a `Ranges<u32>`, the segments
36+
`(Unbounded, Included(42u32))` and `(Included(0), Included(42u32))` as well as
37+
`(Included(1), Included(5))` and `(Included(1), Included(3)) + (Included(4), Included(5))`
38+
are reported as unequal, even though the match the same versions: We can't tell that there isn't a version between `0`
39+
and `-inf` or `3` and `4` respectively.
40+
41+
## Optional features
42+
43+
* `serde`: serialization and deserialization for the version range, given that the version type also supports it.
44+
* `proptest`: Exports are proptest strategy for `Ranges<u32>`.

version-ranges/number-line-ranges.svg

Lines changed: 50 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)