Phone-type
A comprehensive Rust crate for handling phone numbers with advanced E.164 support and compile-time country code resolution.
Features
- 🔢 Basic Phone Validation: String wrapper with format validation
- 📱 E.164 Support: Full E.164 international phone number parsing
- 🌍 Compile-time Country Codes: Perfect Hash Functions for zero-runtime-cost country lookup
- 🚀 Performance: Country codes resolved at compile time using official data
- 📋 Rich Metadata: Country names, ISO codes, and formatting options
- 🔧 Serde Support: Built-in serialization/deserialization (feature-gated)
Install
Add in Cargo.toml:
= "1.0.0-beta.1"
Or run in your project directory:
Examples
Basic Usage
Use in structures:
use *;
E.164 International Phone Numbers
Important: Enable e164 feature first.
use Phone;
Advanced E.164 Examples
use Phone;
Features
This crate provides the following features:
serde- Serialization/deserialization supporte164- E.164 international phone number support with compile-time country codes
Important: No features are enabled by default. You must explicitly enable the features you need.
Enable Specific Features
= { = "1.0.0-beta.1", = ["serde", "e164"] }
Performance
The E.164 functionality uses Perfect Hash Functions (PHF) to resolve country codes at compile time. This means:
- 🚀 Zero runtime cost for country code lookup
- 📊 O(1) lookup time for any country code
- 💾 Minimal memory footprint - data embedded in binary
- 🔄 No external dependencies at runtime
// This lookup happens at compile time!
let phone = from_e_164.unwrap;
let country = phone.country_info.unwrap; // Instant lookup
Serde Support
Serde support is available behind the serde feature:
use ;
use json;
use *;
Country Data Source
The E.164 country codes are sourced from this list and compiled into the binary at build time, ensuring:
- ✅ Accuracy: Based on official ITU-T standards
- 🔄 Completeness: Covers all active country codes
- 🛡️ Reliability: No network dependencies
- 🎯 Efficiency: Optimized for performance
Examples
Run the included examples:
Contributing
Contributions are welcome! The country code data can be updated by modifying data/country_codes.json and rebuilding.