Expand description
This type of formatting can be used for list identifiers when creating ordered
lists similar to HTML’s <ol>
tag. The crate was written to power the
List
widget in Cushy.
This crate’s original implementation was inspired by Typst’s implementation of list numbering. However, this crate is a fresh implementation with newly-written implementations and types.
use nominals::{Decimal, DigitCollection, Error, LetterLower, Nominal};
fn main() {
// Formatting a nominal is as easy as calling to_nominal with the desired
// nominal system.
assert_eq!(0_u32.to_nominal(&Decimal), "0");
// By default, alphabet systems treat their first symbol as 0 in the ones
// place, but treat the first symbol as 1 in every other digit place.
assert_eq!(0_u32.to_nominal(&LetterLower), "a");
assert_eq!(1_u32.to_nominal(&LetterLower), "b");
assert_eq!(26_u32.to_nominal(&LetterLower), "aa");
// This behavior can be changed by using the one_based helper:
assert_eq!(1_u32.to_nominal(&LetterLower.one_based()), "a");
assert_eq!(2_u32.to_nominal(&LetterLower.one_based()), "b");
assert_eq!(27_u32.to_nominal(&LetterLower.one_based()), "aa");
// When a nominal can't be formatted with `to_nominal`, it falls back to
// Decimal.
assert_eq!(0_u32.to_nominal(&LetterLower.one_based()), "0");
assert_eq!(
0_u32.try_to_nominal(&LetterLower.one_based()).unwrap_err(),
Error::NoZeroSymbol
);
}
§no_std
support
This crate is no_std
compatible, and can operate both with and without
alloc
.
§Supported Systems
Decimal
: 0 1 2 3 4 … 9 10 11 12 … 99 100 101 102LetterLower
: a b c d e … z aa ab ac … yz za zb zcLetterUpper
: A B C D E … Z AA AB AC … YZ ZA ZB ZCRomanLower
: i ii iii iv v vi … ix x xi … mmmcmxcix i̅v̅ i̅v̅i … d̅m̅l̅c̅i̅x̅cmxcix m̅ m̅iRomanUpper
: I II III IV V VI … IX X XI … MMMCMXCIX I̅V̅ I̅V̅I … D̅M̅L̅C̅I̅X̅CMXCIX M̅ M̅ICircledNumber
: ⓪ ① ② ③ ④ … ⑨ ⑩ ⑪ ⑫ … ㊽ ㊾ ㊿DoubleCircledNumber
: ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ArmenianLower
: ա բ գ … թ ժ ժա ժբ … ղթ ճ ճաArmenianUpper
: Ա Բ Գ … Թ Ժ ԺԱ ԺԲ … ՂԹ Ճ ՃԱBengali
: ০ ১ ২ ৩ ৪ … ৯ ১০ ১১ ১২ … ৯৯ ১০০ ১০১ ১০২Cambodian
: ០ ១ ២ ៣ ៤ … ៩ ១០ ១១ ១២ … ៩៩ ១០០ ១០១ ១០២SimplifiedChineseInformal
: 零 一 二 … 九 十 十一 … 十九 二十 二十一 … 九十九 一百 一百零一TraditionalChineseInformal
: 零 一 二 … 九 十 十一 … 十九 二十 二十一 … 九十九 一百 一百零一SimplifiedChineseFormal
: 零 一 二 … 九 一十 一十一 … 一十九 二十 二十一 … 九十九 一百 一百零一TraditionalChineseFormal
: 零 一 二 … 九 一十 一十一 … 一十九 二十 二十一 … 九十九 一百 一百零一CjkDecimal
: 〇 一 二 三 四 … 九 一〇 一一 一二 … 九九 一〇〇 一〇一 一〇二CjkEarthlyBranch
: 子 丑 寅 卯 辰 … 亥 一三 一四 一五 … 一四四 一四五 一四六 一四七CjkHeavenlyStem
: 甲 乙 丙 丁 戊 … 癸 一一 一二 一三 … 一〇〇 一〇一 一〇二 一〇三Devanagari
: ० १ २ ३ ४ … ९ १० ११ १२ … ९९ १०० १०१ १०२EasternArabic
: ٠ ١ ٢ ٣ ٤ … ٩ ١٠ ١١ ١٢ … ٩٩ ١٠٠ ١٠١ ١٠٢Ethiopic
: ፩ ፪ ፫ … ፲ ፲፩ ፲፪ … ፺፱ ፻ ፻፩ … ፱፻፺፱ ፲፻ ፲፻፩Georgian
: ა ბ გ … თ ი ია იბ … ჟთ რ რაGreekLower
: α β γ δ ε … ω αα αβ αγ … ψω ωα ωβ ωγGreekUpper
: Α Β Γ Δ Ε … Ω ΑΑ ΑΒ ΑΓ … ΨΩ ΩΑ ΩΒ ΩΓGujarati
: ૦ ૧ ૨ ૩ ૪ … ૯ ૧૦ ૧૧ ૧૨ … ૯૯ ૧૦૦ ૧૦૧ ૧૦૨Gurmukhi
: ੦ ੧ ੨ ੩ ੪ … ੯ ੧੦ ੧੧ ੧੨ … ੯੯ ੧੦੦ ੧੦੧ ੧੦੨HanjaInformal
: 零 一 二 … 九 十 十一 … 十九 二十 二十一 … 九十九 百 百一HangeulFormal
: 영 일 이 … 구 일십 일십일 … 일십구 이십 이십일 … 구십구 일백 일백일HangeulJamo
: ㄱ ㄴ ㄷ ㄹ ㅁ … ㅎ ㄱㄱ ㄱㄴ ㄱㄷ … ㅍㅎ ㅎㄱ ㅎㄴ ㅎㄷHangeulSyllable
: 가 나 다 라 마 … 하 가가 가나 가다 … 파하 하가 하나 하다HanjaFormal
: 零 壹 貳 … 九 壹拾 壹拾壹 … 壹拾九 貳拾 貳拾壹 … 九拾九 壹百 壹百壹Hebrew
: ׳א״ ׳ב״ ׳ג״ … ׳ט״ ׳י״ … יג יד ט״ו ט״ז יז … שצו שצז שצח שצט ׳ת״HexLower
: 0 1 2 3 4 … f 10 11 12 … ff 100 101 102HexUpper
: 0 1 2 3 4 … F 10 11 12 … FF 100 101 102Hiragana
: あ い う え お … ん ああ あい あう … をん んあ んい んうHiraganaIroha
: い ろ は に ほ … す いい いろ いは … せす すい すろ すはJapaneseFormal
: 零 壱 弐 … 九 壱拾 壱拾壱 … 壱拾九 弐拾 弐拾壱 … 九拾九 壱百 壱百壱JapaneseInformal
: 〇 一 二 … 九 十 十一 … 十九 二十 二十一 … 九十九 百 百一Kannada
: ೦ ೧ ೨ ೩ ೪ … ೯ ೧೦ ೧೧ ೧೨ … ೯೯ ೧೦೦ ೧೦೧ ೧೦೨Katakana
: ア イ ウ エ オ … ン アア アイ アウ … ヲン ンア ンイ ンウKatakanaIroha
: イ ロ ハ ニ ホ … ス イイ イロ イハ … セス スイ スロ スハLao
: ໐ ໑ ໒ ໓ ໔ … ໙ ໑໐ ໑໑ ໑໒ … ໙໙ ໑໐໐ ໑໐໑ ໑໐໒Malayalam
: ൦ ൧ ൨ ൩ ൪ … ൯ ൧൦ ൧൧ ൧൨ … ൯൯ ൧൦൦ ൧൦൧ ൧൦൨Mongolian
: ᠐ ᠑ ᠒ ᠓ ᠔ … ᠙ ᠑᠐ ᠑᠑ ᠑᠒ … ᠙᠙ ᠑᠐᠐ ᠑᠐᠑ ᠑᠐᠒Myanmar
: ၀ ၁ ၂ ၃ ၄ … ၉ ၁၀ ၁၁ ၁၂ … ၉၉ ၁၀၀ ၁၀၁ ၁၀၂Oriya
: ୦ ୧ ୨ ୩ ୪ … ୯ ୧୦ ୧୧ ୧୨ … ୯୯ ୧୦୦ ୧୦୧ ୧୦୨Persian
: ۰ ۱ ۲ ۳ ۴ … ۹ ۱۰ ۱۱ ۱۲ … ۹۹ ۱۰۰ ۱۰۱ ۱۰۲Tamil
: ௦ ௧ ௨ ௩ ௪ … ௯ ௧௦ ௧௧ ௧௨ … ௯௯ ௧௦௦ ௧௦௧ ௧௦௨Telugu
: ౦ ౧ ౨ ౩ ౪ … ౯ ౧౦ ౧౧ ౧౨ … ౯౯ ౧౦౦ ౧౦౧ ౧౦౨Thai
: ๐ ๑ ๒ ๓ ๔ … ๙ ๑๐ ๑๑ ๑๒ … ๙๙ ๑๐๐ ๑๐๑ ๑๐๒Tibetan
: ༠ ༡ ༢ ༣ ༤ … ༩ ༡༠ ༡༡ ༡༢ … ༩༩ ༡༠༠ ༡༠༡ ༡༠༢
§Open-source Licenses
This project, like all projects from Khonsu Labs, is open-source. This repository is available under the MIT License or the Apache License 2.0.
To learn more about contributing, please see CONTRIBUTING.md.
Structs§
- A set of additive symbols that form a
NominalSystem
. - Lowercase Armenian numbering.
- Uppercase Armenian numbering.
- Bengali numeric digits.
- Cambodian numeric digits.
- A combination of two
DigitCollection
implementations. - Circled numbers, ranging from 0 to 50.
- CJK Han decimal digits.
- CJK Earthly Branch symbols.
- CJK Heavenly Stems symbols.
- Western ASCII numeric digits.
- Devanagari numeric digits.
- An ordered set of characters that can be treated as digits.
- Doubly-circled numbers, ranging from 1 to 10.
- Eastern Arabic numeric digits.
- A set of enumerated symbols that form a
NominalSystem
. - Ethiopic numerical system.
- Traditional Georgian numbering.
- Greek lowercase alphabet.
- Greek uppercase alphabet.
- Gujarati numeric digits.
- Gurmukhi numeric digits.
- Korean Hangeul/Hangul numbering.
- Korean Hangeul/Hangul Jamo alphabet.
- Korean Hangeul/Hangul alphabet as pronounced.
- Formal Korean Hanja numbering.
- Informal Korean Hanja numbering.
- Hebrew numerals.
- Hexadecimal lower ASCII characters.
- Hexadecimal uppercase ASCII characters.
- Japanese Hiragana Aiueo alphabet.
- Japanese Hiragana Iroha alphabet.
- Formal Japanese Kanji numbering.
- Informal Japanese Kanji numbering.
- Kannada numeric digits.
- Japanese Katakana Aiueo alphabet.
- Japanese Katakana Iroha alphabet.
- Khmer numeric digits.
- Lao numeric digits.
- ASCII lowercase characters.
- ASCII uppercase characters.
- Malayalam numeric digits.
- Mongolian numeric digits.
- Myanmar numeric digits.
- An empty
DigitCollection
that is intended to be used to indicate no fallback should be used as aDigitCollection::Fallback
. - A string that can contain most formatted nominals without a heap allocation.
- Begins counting at 1 when formatting a nominal identifier.
- Oriya numeric digits.
- Was unable to allocate additional memory.
- Persian numeric digits.
- Restricts a set of digits to a specific length.
- Lowercase Roman numerals.
- Uppercase Roman numerals
- Simplified Chinese Formal numerical system.
- Simplified Chinese Informal numerical system.
- Tamil numeric digits.
- Telugu numeric digits.
- Thai numeric digits.
- Tibetan numeric digits.
- Traditional Chinese Formal numerical system.
- Traditional Chinese Informal numerical system.
- Urdu numeric digits.
Enums§
- Error types that can arise from formatting nominals in this crate.
Traits§
- An ordered collection of digits that can be used as a
NominalSystem
. - A type that can be formatted with a
NominalSystem
. - A system of ordered nominal identifiers.
- An unsigned integer type.
- Converts a result from one error type to an
Error<N>
.