pub fn compare_spec_ids(a: &str, b: &str) -> OrderingExpand description
Compare two spec IDs with numeric sorting for member specs and base36 sequences.
This function provides a natural sort order where member spec numbers and base36 sequence portions are compared numerically rather than lexicographically. This ensures:
- Specs like
2026-01-25-00y-abc.10sort after2026-01-25-00y-abc.2 - Specs like
2026-01-25-010-xxxsort after2026-01-25-00z-yyy
§Sorting behavior
- For non-member specs, parses date/sequence/suffix and compares sequence numerically
- For member specs (with
.Nsuffix), compares the base ID using date/sequence/suffix parsing first, then compares member numbers numerically - Mixed member/non-member specs: non-members sort before members with the same base
§Examples
ⓘ
use std::cmp::Ordering;
assert_eq!(compare_spec_ids("2026-01-25-00y-abc.2", "2026-01-25-00y-abc.10"), Ordering::Less);
assert_eq!(compare_spec_ids("2026-01-25-00y-abc.10", "2026-01-25-00y-abc.2"), Ordering::Greater);
assert_eq!(compare_spec_ids("2026-01-25-00y-abc", "2026-01-25-00y-def"), Ordering::Less);
assert_eq!(compare_spec_ids("2026-01-25-00y-abc", "2026-01-25-00y-abc.1"), Ordering::Less);
assert_eq!(compare_spec_ids("2026-01-25-010-xxx", "2026-01-25-00z-yyy"), Ordering::Greater);