11 个版本
0.3.2 | 2023 年 8 月 26 日 |
---|---|
0.3.1 | 2023 年 8 月 26 日 |
0.2.2 | 2021 年 6 月 12 日 |
0.2.1 | 2021 年 5 月 22 日 |
0.0.1 | 2021 年 4 月 12 日 |
#66 在 无标准库 中
435 每月下载量
20KB
387 行
cpf-rs
巴西 CPF 解析、验证和格式化库。
use cpf::Cpf;
// Use the `valid` function if all you need is validating a CPF number
assert!(cpf::valid("385.211.390-39"));
assert!(cpf::valid("38521139039"));
assert!(!cpf::valid("000.000.000-00"));
// Parse into a Cpf struct if you need formatting or other metadata
let cpf: Cpf = "38521139039".parse()?;
assert_eq!(format!("{cpf}"), "385.211.390-39");
assert_eq!(cpf.as_str(), "38521139039");
assert_eq!(cpf.digits(), [3, 8, 5, 2, 1, 1, 3, 9, 0, 3, 9]);
// Note that the Cpf struct is guaranteed to always be valid
assert!("000.000.000-00".parse::<Cpf>().is_err());
assert!(cpf::valid("385.211.390-39".parse::<Cpf>()?));
支持 no_std
该库不进行动态分配,可以通过禁用 std
标志在 no_std 环境中使用
[dependencies]
cpf = { version = "0.3", default-features = false }
支持随机 CPF 生成
启用 rand
功能标志以启用随机 CPF 生成
[dependencies]
cpf = { version = "0.3", features = ["rand"] }
rand = "0.8"
use cpf::Cpf;
use rand;
use rand::Rng;
let cpf = rand::thread_rng().gen::<Cpf>();
依赖项
~245KB