#integer #literals #roman #numeral #write #localization #consts

roman-literals

使用罗马数字编写整数字面量

3 个不稳定版本

0.2.1 2022年8月28日
0.2.0 2022年8月28日
0.1.0 2022年8月26日

#276 in 值格式化

Unlicense

150KB
4.5K SLoC

roman-literals

roman-literals 提供了一种使用罗马数字编写整数字面量的简单方法。

功能

  • 支持从 I 到 MMMCMXCIX(1 到 3999)的所有整数
  • 使用 roman! 宏进行类型推断
  • 零成本!

使用方法

  • 提供类似于 iXXXII 的类型别名,用于替换原始类型如 [i32].

  • 使用 roman! 宏,字面量的类型会自动推断,默认为 iXXXII。该宏也支持负数;更多信息请参阅 roman!

  • 还提供了常量,例如 III_uXXXII。这些常量都以它们的类型后缀。有关更多信息,请参阅 consts 模块。

示例

use roman_literals::*; // roman! macro and type aliases

let forty_two: uXXXII = roman!(XLII);
assert_eq!(forty_two, 42);

let negative_3999: iXVI = roman!(-MMMCMXCIX);
assert_eq!(negative_3999, -3999);

use roman_literals::consts::*; // to get the constants

let negative_300 = -CCC_iLXIV; // i64
assert_eq!(negative_300, -300);

为什么?

为什么不呢?

依赖项