Skip to content

Latest commit

 

History

History
35 lines (24 loc) · 1.64 KB

README.md

File metadata and controls

35 lines (24 loc) · 1.64 KB

libphonenumber-sys Crates.io

IMPORTANT NOTE: This crate has been deprecated in favour of the native rust port of libphonenumber

This is a very early atempt to create rust ffi bindings to googles excellent libphonenumber. Most of the crate has been autogenerated with cpp_to_rust from the current libphonenumber version 7.7 and then modified to work better with rusts native types.

Example

use libphonenumber_sys::{PhoneNumberUtil,PhoneNumber,PhoneNumberFormat,PhoneNumberUtilError};

//get instance of PhoneNumberUtil
let util = PhoneNumberUtil::get_instance();

//construct a number by hand
let number1 = PhoneNumber::new();
number1.set_country_code(1);
number1.set_national_number(2128322000);

//check if number is valid
assert_eq!(util.is_valid_number(&number1), true);

//parse a number from a string
let number2 = util.parse("(800) 1234-5678","US").unwrap();

assert_eq!(number2.country_code(), 1);
assert_eq!(number2.national_number(), 80012345678);

//format a number as E164 string
let e164 = util.format(&number2, PhoneNumberFormat::E164);

assert_eq!(e164, "+180012345678");

Status

Many functions are not properly implemented yet. Not all objects have working initializers yet. Functions that take or emit std::strings require additional modifications to the c wrapper. Variants of functions that correctly handle std::strings are suffixed with "_Str"