ord_subset/
lib.rs

1//! Ever wanted to call `.max()` on an iterator of floats? Now you can! Well, almost: `.ord_subset_max()`.
2//!
3//! This crate is for types like the float primitive types `f32` and `f64`: Types that are totally ordered *except for these particular values*.
4//!
5//! I call these types subset-ordered. They can be marked with the `OrdSubset` trait that this crate defines.
6//! Such types can be put in the `OrdVar` struct. Wrapping your value in this marks to other code that the contents are ordered, thus fulfilling generic `Ord` trait bounds.
7//!
8//! For convenience, iterators and slices are extended so that `OrdSubset` types have access to methods equivalent to `.max()` and `.sort()`.
9//! Values in the unordered subset of a type that is `OrdSubset` are handled in a consistent manner (Ignored or put at the end).
10//!
11//! # Usage
12//!
13//! Add this to your `Cargo.toml`:
14//!
15//! ```toml
16//! [dependencies]
17//! ord_subset = "3"
18//! ```
19//!
20//!
21//! ```
22//! use ord_subset::{OrdSubsetIterExt, OrdSubsetSliceExt};
23//!
24//! // Slices. Works on vector, too.
25//! let mut s = [5.0, std::f64::NAN, 3.0, 2.0];
26//! s.ord_subset_sort_unstable();
27//! assert_eq!(&s[0..3], &[2.0, 3.0, 5.0]);
28//! assert_eq!(s.ord_subset_binary_search(&5.0), Ok(2));
29//!
30//! // iterators
31//! assert_eq!( s.iter().ord_subset_max(), Some(&5.0) );
32//! assert_eq!( s.iter().ord_subset_min(), Some(&2.0) );
33//! ```
34//!
35//! # License
36//! Licensed under the Apache License, Version 2.0
37//! <https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
38//! <https://opensource.org/licenses/MIT>, at your
39//! option. This file may not be copied, modified, or distributed
40//! except according to those terms.
41//#![cfg_attr(feature="unstable", unstable)]
42#![cfg_attr(not(feature = "std"), no_std)]
43#[cfg(feature = "std")] // attribute not necessary, but rls warns without
44extern crate core;
45
46mod iter_ext;
47mod ord_subset_trait;
48mod ord_var;
49mod slice_ext;
50
51pub use iter_ext::*;
52pub use ord_subset_trait::*;
53pub use ord_var::*;
54pub use slice_ext::*;