ordered-float
Wrapper types that give Rust's IEEE-754 floats a total ordering for sorting and hashing
Repository Health
Technical Analysis
ordered-float provides OrderedFloat and NotNan wrapper types that implement Ord, Eq, and Hash for floating-point numbers, which Rust’s native f32/f64 types cannot do because of NaN’s IEEE-754 comparison semantics. This lets floats be used as keys in BTreeMap/HashMap, sorted with the standard library’s sort functions, and compared with <, ==, and friends without runtime panics or partial-ordering workarounds.
What You Get
OrderedFloat<T>giving any float type a total order (NaN sorts consistently rather than being incomparable)NotNan<T>which enforces at construction time that the wrapped value is never NaN, returning aResultotherwiseHashimplementations for both wrapper types, enabling floats asHashMap/HashSetkeys- Optional integrations behind feature flags for
serde,rand,arbitrary,bytemuck,rkyv,schemars, andproptest no_stdsupport via thelibmfeature for embedded and constrained environments
Common Use Cases
- Sorting a
Vec<f64>of scores, prices, or measurements without a custom comparator - Using floating-point values as keys in a
BTreeMaporHashMap(e.g. for a priority queue keyed by a float weight) - Guaranteeing at the type level that a float field can never be NaN via
NotNan - Serializing/deserializing float-keyed collections with serde in scientific or numerical Rust codebases
Under The Hood
Architecture - The crate is a single lib.rs module (~3000 lines including tests) defining two core newtypes, OrderedFloat<T> and NotNan<T>, each implementing Ord/Eq/Hash by treating NaN as a well-defined sort position rather than propagating IEEE-754’s incomparability, with NotNan additionally enforcing a construction-time invariant via Result-returning constructors. Tech Stack - Pure Rust, no_std-compatible (with an optional libm feature for math without the standard library), depending only on num-traits by default, with a long list of optional integration crates (serde, rand, arbitrary, bytemuck, rkyv, rkyv_08, schemars, speedy, derive-visitor) gated behind Cargo feature flags to keep the default dependency footprint minimal. Code Quality - The tests/ directory and inline unit tests cover both wrapper types, NaN edge cases, and each optional feature integration individually (e.g. serde round-tripping, proptest-based property tests), with rustfmt.toml enforcing consistent formatting across the small codebase. API Design - The API surface is deliberately minimal and idiomatic: both types implement the standard comparison/hash traits so they slot into existing generic code (sorted collections, hash maps) with zero special-casing, and NotNan::new() returning Result<Self, FloatIsNan> follows Rust’s fallible-construction convention rather than panicking.
Used by 8 apps in this directory
Arroyo
Data Engineering · Analytics
A distributed stream processing engine written in Rust that lets you write SQL to run stateful, real-time computations over data streams with subsecond results.
Fern
Developer Tools
Fern turns a single OpenAPI, AsyncAPI, or Protobuf definition into type-safe SDKs for nine languages and a hosted API documentation site, all from one CLI and one source of truth.
InfluxDB
Databases · Analytics
Open-source time-series database built for real-time ingest, fast SQL queries, and embedded Python automation — powered by Apache Arrow and Parquet.
liteparse
Developer Tools
A fast, lightweight, open-source document parser that extracts spatial text, bounding boxes, and Markdown from PDFs and Office files — entirely on your machine.
Meilisearch
Search
Lightning-fast hybrid search engine with AI-powered semantic and full-text retrieval for modern applications.
ParadeDB
Search · Databases · Analytics
Born out of Y Combinator's S2023 batch, ParadeDB is a Postgres extension that delivers Elasticsearch-quality BM25 search and real-time analytics without a separate search cluster to manage.
PostHog
Analytics · Monitoring · Developer Tools
The all-in-one open source product platform combining analytics, session replay, feature flags, error tracking, AI observability, and a built-in data warehouse in a single self-hostable stack.
Volga
Data Engineering
A Rust-based real-time data processing engine for AI/ML feature computation, built on Apache DataFusion and Arrow — positioned as an alternative to Flink, Spark, Chronon, and OpenMLDB with unified streaming, batch, and request-time execution.