fmt-cmp

Crates.iofmt-cmp
lib.rsfmt-cmp
version0.1.1
sourcesrc
created_at2021-12-29 08:24:39.063207
updated_at2022-01-07 19:29:38.786376
descriptionTraits and utilities for lexicographically comparing values in their `Display` representations
homepage
repositoryhttps://github.com/tesaguri/fmt-cmp.git
max_upload_size
id504690
size58,139
Daiki Mizukami (tesaguri)

documentation

README

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.

Commit count: 15

cargo fmt