Skip to content

copyleftdev/fast_e164

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

fast_e164

A high-performance Rust library for validating, normalizing, parsing, and formatting phone numbers according to the E.164 international standard.

License: MIT Crates.io Build Status

Features

  • Constant-time validation: Validate E.164 numbers with zero allocations
  • 🗺️ Country-aware normalization: Convert various phone formats to E.164
  • 🧩 Structured parsing: Extract country codes and national numbers
  • 🖨️ Local formatting: Format numbers according to local conventions
  • 🛡️ No-std compatible: Use in embedded systems and WebAssembly
  • 🧰 CLI tool: Batch processing and interactive usage
  • 🌐 FFI-ready: Bindings for Go, Python, and C
  • 📊 Benchmarked: Extensively tested for performance

Quick Start

Add to your Cargo.toml:

[dependencies]
fast_e164 = "0.1.0"

Example usage:

use fast_e164::{is_valid_e164, normalize_to_e164, parse_e164, format_local};

// Validate an E.164 number
assert!(is_valid_e164("+14155552671"));

// Normalize a phone number to E.164
let e164 = normalize_to_e164("(415) 555-2671", "US").unwrap();
assert_eq!(e164, "+14155552671");

// Parse a phone number into its components
let phone = parse_e164("+14155552671").unwrap();
assert_eq!(phone.country_code, 1);
assert_eq!(phone.national_number, "4155552671");
assert_eq!(phone.iso_country, Some("US".to_string()));

// Format a phone number in local style
let local = format_local(&phone);
assert_eq!(local, "(415) 555-2671");

CLI Usage

The fast-e164 CLI tool can be installed with:

cargo install fast_e164 --features cli

CLI Commands

# Validate a phone number
fast-e164 validate "+14155552671"

# Normalize a phone number to E.164
fast-e164 normalize "(415) 555-2671" --country US

# Parse a phone number and display info
fast-e164 parse "+14155552671"

# Show detailed metadata
fast-e164 info "+14155552671"

# Process batch CSV file
fast-e164 batch --input phones.csv --output normalized.csv --column phone_number --country US

# Generate test data
fast-e164 testgen --countries US,GB,DE --count 1000 --output test_vectors.csv

Feature Flags

Feature Description Dependencies
default Core validation/parsing (no_std compatible) None
metadata Country metadata and carrier detection serde, phf
wasm WebAssembly bindings wee_alloc, wasm-bindgen
ffi Foreign Function Interface pyo3, cbindgen
cli Command-line interface clap, csv, serde
testgen Test data generation metadata

Performance

Benchmarked on an Intel i7-10700K @ 3.8GHz:

Function Throughput Memory
is_valid_e164 3.2M ops/sec 0 alloc
normalize_to_e164 800K ops/sec 1 alloc/op
parse_e164 1.1M ops/sec 2 alloc/op
CLI Batch (CSV) 50K rows/sec ~3MB RSS

Comparison to Other Libraries

fast_e164 focuses on being lightweight and high-performance, especially suitable for validation and normalization tasks. Unlike more comprehensive libraries like phonenumber or Google's libphonenumber, it prioritizes speed and low memory usage over complete feature parity.

Library Binary Size Validation Speed Parse Speed Features
fast_e164 120KB 3.2M ops/sec 1.1M ops/sec ⭐⭐⭐
phonenumber 2.1MB 180K ops/sec 150K ops/sec ⭐⭐⭐⭐⭐
libphonenumber 4.5MB 90K ops/sec 75K ops/sec ⭐⭐⭐⭐⭐

Contributing

Contributions are welcome! Check out the DESIGN.md file for architectural details and project structure.

License

MIT License - See LICENSE for details.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages