12 个版本
| 新增 0.5.0 | 2024 年 8 月 19 日 |
|---|---|
| 0.4.4 | 2023 年 8 月 26 日 |
| 0.4.3 | 2022 年 6 月 7 日 |
| 0.4.2 | 2021 年 8 月 9 日 |
| 0.2.0 | 2019 年 10 月 13 日 |
1 在 金融 类别中
19,712 每月下载量
在 18 个crate中使用 (16个直接使用)
42KB
822 代码行
ISO 4217 货币代码
此crate提供了一个枚举,表示所有ISO 4217货币,并具有简单的将数字代码和字符代码、使用每种货币的领土列表、货币符号以及货币的英文名称之间进行转换的方法。
这些数据来自 https://en.wikipedia.org/wiki/ISO_4217
从唯一的依赖项 - iso_country crate - 导出 Country 枚举。
功能
crate有一些可选功能
with-serdeiteratorwith-schemarswith-sqlx-sqlitewith-sqlx-postgreswith-sqlx-mysql
with-serde
如果您需要使用serde进行序列化/反序列化支持,则应在iso_currency的依赖项中包含此功能。
这将使serde在Currency上派生Serialize和Deserialize。
iterator
如果您在iso_currency上指定iterator功能,它将在Currency上派生strum的 EnumIter trait,这提供对所有变体的迭代器。以下是一个示例用法
use iso_currency::IntoEnumIterator;
let mut iter = Currency::iter();
with-schemars
如果您需要为项目生成JSON模式,可以使用with-schemars功能。这将使Currency上的schemars JsonSchema trait派生。
注意:此功能启用了with-serde。
with-sqlx-sqlite
在Currency结构上实现来自sqlx版本>0.7的Type和Decode trait,用于SQLite。
with-sqlx-postgres
在Currency结构上实现来自sqlx版本>0.7的Type和Decode trait,用于PostgreSQL。
with-sqlx-mysql
在Currency结构体上实现了来自sqlx版本 >0.7 的 Type 和 Decode 特性。
示例
use iso_currency::{Currency, Country};
assert_eq!(Currency::EUR.name(), "Euro");
assert_eq!(Currency::EUR.numeric(), 978);
assert_eq!(Currency::from_numeric(978), Some(Currency::EUR));
assert_eq!(Currency::from_code("EUR"), Some(Currency::EUR));
assert_eq!(Currency::CHF.used_by(), vec![Country::LI, Country::CH]);
assert_eq!(format!("{}", Currency::EUR.symbol()), "€");
assert_eq!(Currency::EUR.subunit_fraction(), Some(100));
assert_eq!(Currency::JPY.exponent(), Some(0));
想帮助改进数据吗?
Currency 枚举及其实现是从 isodata.tsv 文件生成的。它是一个以制表符分隔的值表。如果你想更正某些值或添加缺失的值,你只需提交一个编辑该表的拉取请求即可。
需要注意的一点是,即使是可选字段缺失,每行的字段数量也应该始终相同。这意味着你应在每一行中拥有 6 个制表符。
used_by_alpha2 列略有不同。它可以空着,但如果不是空着,则包括一个以分号分隔的列表(没有尾随的分号),列表中包含所有大写的 ISO 3166-1 两位国家代码。
依赖项
~0.1–14MB
~186K SLoC