项目作者: rustonaut

项目描述 :
Library for parsing, formatting and validating international phone numbers.
高级语言: Rust
项目地址: git://github.com/rustonaut/rust-phonenumber.git
创建时间: 2017-06-29T10:30:17Z
项目社区:https://github.com/rustonaut/rust-phonenumber

开源协议:Apache License 2.0

下载


phonenumber

CI Build
Crates.io
phonenumber
License

Rust version of libphonenumber.
We currently require 1.58.0 as minimum supported Rust version (MSRV).

Usage

Add this to your Cargo.toml:

  1. [dependencies]
  2. phonenumber = "0.3"

Example

The following example parses, validates and formats the given phone number.

  1. use phonenumber::Mode;
  2. use std::env;
  3. fn main() {
  4. let mut args = env::args().skip(1).collect::<Vec<_>>();
  5. if args.len() < 1 {
  6. panic!("not enough arguments");
  7. }
  8. let number = args.pop().unwrap();
  9. let country = args.pop().map(|c| c.parse().unwrap());
  10. let number = phonenumber::parse(country, number).unwrap();
  11. let valid = phonenumber::is_valid(&number);
  12. if valid {
  13. println!("\x1b[32m{:#?}\x1b[0m", number);
  14. println!();
  15. println!("International: {}", number.format().mode(Mode::International));
  16. println!(" National: {}", number.format().mode(Mode::National));
  17. println!(" RFC3966: {}", number.format().mode(Mode::Rfc3966));
  18. println!(" E.164: {}", number.format().mode(Mode::E164));
  19. }
  20. else {
  21. println!("\x1b[31m{:#?}\x1b[0m", number);
  22. }
  23. }