sys libphonenumber-sys

rust ffi bindings to libphonenumber

2 releases

Uses old Rust 2015

0.1.1 Nov 14, 2016
0.1.0 Nov 14, 2016

MIT license

11K SLoC

Rust 9K SLoC // 0.0% comments C++ 2K SLoC


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. Many functions are not properly implemented yet, especially the ones that take or emit std::strings, as they require additional modifications to the c wrapper.


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();

//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");