#range #set-operations #set #intersection #union #serde-derive

rangetools

Extending the Rust Range structs found in std::ops

5 releases

0.1.4 May 6, 2023
0.1.3 Mar 27, 2023
0.1.2 Mar 19, 2023
0.1.1 Dec 28, 2021
0.1.0 Dec 15, 2021

#9 in #intersection

Download history 58/week @ 2024-08-03 27/week @ 2024-08-10 438/week @ 2024-08-17 50/week @ 2024-08-24 37/week @ 2024-08-31 114/week @ 2024-09-07 71/week @ 2024-09-14 134/week @ 2024-09-21 59/week @ 2024-09-28 20/week @ 2024-10-05 111/week @ 2024-10-12 149/week @ 2024-10-19 81/week @ 2024-10-26 72/week @ 2024-11-02 92/week @ 2024-11-09 127/week @ 2024-11-16

386 downloads per month
Used in prng_split

MIT/Apache

350KB
11K SLoC

Rangetools

Traits extending the Rust Range structs in std::ops

Usage

Add this to your Cargo.toml:

[dependencies]
rangetools = "0.1"

How to use in your crate:

use rangetools::Rangetools;

This provides new methods on all of the std::ops range types, as well as any types introduced in this crate to manage the outputs of such methods.

let i = (0..5).intersection(3..);
assert!(i.contains(4));

let i2 = (0..5).intersection(5..10);
assert!(i2.is_empty());

Wherever possible (when the result is lower-bounded), the resulting types of these operations implement IntoIterator so that more operations can be performed on them.

let u1 = (1..3).union(5..7);
assert_eq!(u1.into_iter().collect::<Vec<_>>(), vec![1, 2, 5, 6]);

let u2 = (1..3).union(10..);
assert_eq!(u2.into_iter().take(5).collect::<Vec<_>>(), vec![1, 2, 10, 11, 12]);

let c = (1..3).complement();
let i = c.into_iter(); // Compiler error! The result has no lower bound
                       // and thus cannot be iterated over.

Features

The serde feature provides derives for serde's Serialize and Deserialize traits.

License

Licensed under the Apache License, Version 2.0 or the MIT license, at your option.

Dependencies

~155KB