#sorting #fmt #display #representation #compare #cmp #utilities

no-std fmt-cmp

Traits and utilities for lexicographically comparing values in their Display representations

3 releases

0.1.2 Jul 28, 2024
0.1.1 Jan 7, 2022
0.1.0 Dec 29, 2021

#287 in Rust patterns

Download history 193/week @ 2024-07-25 216/week @ 2024-08-01 32/week @ 2024-08-08 28/week @ 2024-08-15 24/week @ 2024-08-22 202/week @ 2024-08-29 223/week @ 2024-09-05 71/week @ 2024-09-12 126/week @ 2024-09-19 331/week @ 2024-09-26 150/week @ 2024-10-03 122/week @ 2024-10-10 165/week @ 2024-10-17 109/week @ 2024-10-24 146/week @ 2024-10-31 230/week @ 2024-11-07

660 downloads per month
Used in 4 crates (2 directly)

MIT/Apache

43KB
767 lines

fmt-cmp

GitHub Actions (CI) crates.io docs.rs Rust 1.41.0+

A Rust library for lexicographically comparing values in their Display representations.

The utilities provided by this library gives the same results as comparing values after applying to_string(), but they never allocate on the heap memory.

Examples

Compare digits of numbers:

assert!(fmt_cmp::eq(f64::NAN, f64::NAN)); // `"NaN" == "NaN"`
assert!(fmt_cmp::cmp(&42, &240).is_gt()); // `"42" > "240"`

Sorting integers lexicographically:

use std::collections::BTreeSet;

use fmt_cmp::Cmp as FmtCmp;

let mut values: BTreeSet<FmtCmp<u32>> = (1..=10).map(FmtCmp).collect();
assert!(values
   .into_iter()
   .map(|cmp| cmp.0)
   .eq([1, 10, 2, 3, 4, 5, 6, 7, 8, 9]));

License

Copyright (c) 2021 Daiki "tesaguri" Mizukami

This project is licensed under either of:

at your option.

No runtime deps