docs.rs failed to build hanzi-sort-0.2.1
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
Please check the build logs for more information.
See Builds for ideas on how to fix a failed build, or Metadata for how to configure docs.rs builds.
If you believe this is docs.rs' fault, open an issue.
hanzi-sort
Sort Chinese text the way Chinese readers expect.
hanzi-sort is a Rust CLI and library for sorting Hanzi by Hanyu Pinyin or by stroke count, with deterministic tie-breaking, phrase-level override rules for polyphonic characters, and terminal-friendly tabular output.
Migration note
pinyin-sorthas been renamed tohanzi-sort. This is a hard rename: there is no compatibility binary alias.
Why it exists
Unicode codepoint order is not Chinese sort order.
If you want useful output for names, glossaries, study lists, or publishing workflows, you usually need more than plain lexical comparison:
- pinyin order for alphabetic-style indexes
- stroke order for dictionary-style or teaching workflows
- phrase-level override rules for polyphonic characters like
重庆or银行 - stable tie-breaking so the same dataset always produces the same order
Quick examples
Install the CLI:
Sort by pinyin:
Sort by stroke count:
Resolve a polyphonic phrase with an override file:
Features
- Sort by
pinyinorstrokes(default), or opt in tojyutping,zhuyin,radicalvia cargo features - Read from stdin when no input flags are given (
cat names.txt | hanzi-sort) - Keep unknown characters in the comparison key instead of dropping them
- Break ties by original character so output stays deterministic
- Override single characters or full phrases with TOML
- Format output with configurable columns, alignment, padding, separators, and blank-line cadence
- Reuse the same core sorter from Rust via
PinyinCollator,StrokesCollator, and theCollatortrait
Opt-in collators
# pinyin + strokes only (default)
# add Cantonese Jyutping (Unihan kCantonese)
# add Mandarin Zhuyin / Bopomofo
# add Kangxi radical sort (Unihan kRSUnicode)
# everything
Library usage
use ;
let sorted = sort_strings_with;
use AnyCollator;
let sorted = pinyin.sort;
Learn more
- Repository: https://github.com/Acture/hanzi-sort
- Documentation: https://docs.rs/hanzi-sort
- License: https://github.com/Acture/hanzi-sort/blob/master/LICENSE