#range #version #selector #pubgrub

version-ranges

Performance-optimized type for generic version ranges and operations on them

1 unstable release

new 0.1.0 Oct 29, 2024

#817 in Rust patterns

Download history 409/week @ 2024-10-29

409 downloads per month
Used in 6 crates (2 directly)

MPL-2.0 license

49KB
813 lines

This crate contains a performance-optimized type for generic version ranges and operations on them.

Ranges can represent version selectors such as (>=1, <2) OR (==3) OR (>4). Internally, it is an ordered list of contiguous intervals (segments) with inclusive, exclusive or open-ended ends, similar to a Vec<(Bound<T>, Bound<T>)>.

You can construct a basic range from one of the following build blocks. All other ranges are concatenation, union, and complement of these basic ranges.

Ranges is generic over any type that implements [Ord] + Clone and can represent all kinds of slices with ordered coordinates, not just version ranges. While built as a performance-critical piece of pubgrub, it can be adopted for other domains, too.

Note that there are limitations to the equality implementation: Given a Ranges<u32>, the segments (Unbounded, Included(42u32)) and (Included(0), Included(42u32)) as well as (Included(1), Included(5)) and (Included(1), Included(3)) + (Included(4), Included(5)) are reported as unequal, even though the match the same versions: We can't tell that there isn't a version between 0 and -inf or 3 and 4 respectively.

Optional features

  • serde: serialization and deserialization for the version range, given that the version type also supports it.
  • proptest: Exports are proptest strategy for Ranges<u32>.

Dependencies

~43–740KB
~14K SLoC