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无标准库

Download history 97/week @ 2024-03-09 72/week @ 2024-03-16 134/week @ 2024-03-23 65/week @ 2024-03-30 37/week @ 2024-04-06 117/week @ 2024-04-13 102/week @ 2024-04-20 11/week @ 2024-04-27 24/week @ 2024-05-04 157/week @ 2024-05-11 239/week @ 2024-05-18 83/week @ 2024-05-25 75/week @ 2024-06-01 125/week @ 2024-06-08 104/week @ 2024-06-15 130/week @ 2024-06-22

435 每月下载量

MIT 许可证

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