#fmt #cmp #representation #display #values #comparing #compare

no-std fmt-cmp

Traits and utilities for lexicographically comparing values in their Display representations

2 releases

0.1.1 Jan 7, 2022
0.1.0 Dec 29, 2021

#1682 in Rust patterns

Download history 20/week @ 2023-12-18 25/week @ 2024-01-08 36/week @ 2024-01-15 12/week @ 2024-01-29 21/week @ 2024-02-05 14/week @ 2024-02-12 57/week @ 2024-02-19 34/week @ 2024-02-26 34/week @ 2024-03-04 23/week @ 2024-03-11 56/week @ 2024-03-18 50/week @ 2024-03-25 113/week @ 2024-04-01

247 downloads per month
Used in 2 crates (via oauth1-request)

MIT/Apache

42KB
766 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