odsek/lib.rs
1//! # Lazy interval-set composition
2//!
3//! `odsek` provides allocation-free, pull-based composition of ordered,
4//! non-overlapping mathematical interval sets. Each [`Interval`] carries a
5//! value, so intersections and unions can also be read as joins over tagged
6//! segments.
7//!
8//! The core API is `no_std` and does not allocate. Streams are queried through
9//! [`Intervals::head`], which returns the next interval after a requested
10//! position; iteration and combinators are layered on top of that primitive.
11//!
12//! ## Endpoint flavors
13//!
14//! * [`EndpointOC`] supports explicitly open or closed boundaries.
15//! * [`EndpointSymmetric`] represents the common `[a, b)` convention: closed
16//! on the left, open on the right.
17//!
18//! ## Composition
19//!
20//! With the default `operators` feature, `&` computes intersection and `|`
21//! computes union. Disable default features to use the explicit [`and`] and
22//! [`or`] functions instead.
23//!
24//! ## Examples
25//!
26//! ```
27//! use odsek::*;
28//!
29//! let ia = Interval::new(EndpointOC::Closed(1), EndpointOC::Closed(3), "A");
30//! let ib = Interval::new(EndpointOC::Open(2), EndpointOC::Open(4), "B");
31//!
32//! let isa = IntervalsSingle::new(ia);
33//! let isb = IntervalsSingle::new(ib);
34//!
35//! let and_ab = and(isa, isb);
36//! let and_ab_vec = and_ab.into_iter().collect::<Vec<_>>();
37//!
38//! assert_eq!(and_ab_vec.len(), 1);
39//! assert_eq!(and_ab_vec[0], Interval::new(EndpointOC::Open(2), EndpointOC::Closed(3), ("A","B")));
40//! ```
41
42// no_std when not testing
43#![cfg_attr(not(test), no_std)]
44
45mod interval;
46pub use self::interval::*;
47
48mod endpointoc;
49mod endpointsymmetric;
50
51mod endpoint;
52pub use self::endpoint::*;
53
54pub(crate) mod ivs;
55pub use self::ivs::*;
56
57mod iterator;
58pub use self::iterator::*;