Crates.io | phonelib |
lib.rs | phonelib |
version | 0.1.2 |
source | src |
created_at | 2023-12-09 20:38:40.006455 |
updated_at | 2024-03-20 08:13:34.55948 |
description | A library that helps you work with phone numbers |
homepage | |
repository | https://github.com/mohamadzoh/phonelib |
max_upload_size | |
id | 1063885 |
size | 40,093 |
Phonelib is a Rust library for handling phone numbers. It provides functions for validation, cleaning, and extracting country information from phone numbers.
Add this to your Cargo.toml
:
[dependencies]
phonelib = "0.1.2"
pub struct Country {
pub name: &'static str,
pub code: &'static str,
pub phone_lengths: &'static [u8],
pub prefix: u32,
}
extern crate phonelib
let phone_number = "+96179123123".to_string();
if phonelib::is_valid_phone_number(&phone_number) {
println!("{} is a valid phone number.", phone_number);
} else {
println!("{} is not a valid phone number.", phone_number);
}
let phone_number = "+11231231232".to_string();
match phonelib::extract_country(&phone_number) {
Some(country) => {
println!("Country code for {} is: {}", phone_number, country.code);
}
None => println!("Unable to extract country information for {}", phone_number),
}
let phone_number = "+096179123123".to_string();
match phonelib::normalize_phone_number(&phone_number) {
Some(cleaned) => println!("Cleaned phone number: {}", cleaned),
None => println!("Invalid characters in the phone number."),
}
// Example 3: Cleaning a phone number in place
let mut phone_number = "+0012345678912".to_string();
match phonelib::normalize_phone_number_in_place(&mut phone_number) {
Some(_) => println!("Cleaned phone number in place: {}", phone_number),
None => println!("Invalid characters in the phone number."),
}
Rusty Rails is a larger project aiming to bridge the gap between Rust and Ruby/Ruby on Rails. We are actively working on recreating ruby library into rust that seamlessly make working in rust more easy and fun for new developers.
Contributions to the Phonelib library are welcome! Feel free to open issues, submit pull requests, or provide feedback to help improve this library.