Skip to content

Commit 4b07e85

Browse files
authored
Merge branch 'main' into gabriel/mnc-mcc
2 parents bfd8fab + 928bb3f commit 4b07e85

File tree

18 files changed

+127
-103
lines changed

18 files changed

+127
-103
lines changed

.github/workflows/build.yml

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,14 @@ jobs:
2424
matrix:
2525
toolchain: ["stable", "beta"]
2626
coverage: [false]
27+
tests: [true]
2728
include:
2829
- toolchain: "nightly"
2930
coverage: true
31+
tests: true
32+
- toolchain: "1.58.0"
33+
coverage: false
34+
tests: false
3035
steps:
3136
- name: Checkout repository
3237
uses: actions/checkout@v2
@@ -39,22 +44,30 @@ jobs:
3944
- name: Configure CI cache
4045
uses: Swatinem/rust-cache@v2
4146

42-
- name: Build
47+
- name: Build all targets
4348
uses: actions-rs/cargo@v1
49+
if: ${{ matrix.tests }}
4450
with:
4551
command: build
4652
args: --all-targets
4753

54+
- name: Build
55+
uses: actions-rs/cargo@v1
56+
if: ${{ !matrix.tests }}
57+
with:
58+
command: build
59+
args: --lib --all-features
60+
4861
- name: Run tests
4962
uses: actions-rs/cargo@v1
50-
if: ${{ !matrix.coverage }}
63+
if: ${{ !matrix.coverage && matrix.tests }}
5164
with:
5265
command: test
5366
args: --all-targets --no-fail-fast
5467

5568
- name: Run tests
5669
uses: actions-rs/cargo@v1
57-
if: ${{ matrix.coverage }}
70+
if: ${{ matrix.coverage && matrix.tests }}
5871
with:
5972
command: test
6073
args: --all-targets --no-fail-fast

Cargo.toml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,32 @@ readme = "README.md"
1616
bincode = "1.3"
1717
either = "1.8"
1818
fnv = "1.0"
19-
itertools = ">=0.10, <=0.11"
2019
lazy_static = "1.4"
20+
itertools = ">=0.10, <= 0.12"
2121
nom = "7.1"
22-
quick-xml = "0.28"
22+
quick-xml = ">=0.28, <= 0.31"
2323
regex = "1.7"
2424
regex-cache = "0.2"
2525
serde = "1.0"
2626
serde_derive = "1.0"
27-
strum = { version = "0.24", features = ["derive"] }
27+
strum = { version = ">=0.24, <=0.25", features = ["derive"] }
2828
thiserror = "1.0"
2929

3030
[build-dependencies]
3131
bincode = "1.3"
32-
quick-xml = "0.28"
32+
quick-xml = ">=0.28, <=0.31"
3333
regex = "1.7"
3434
serde = "1.0"
3535
serde_derive = "1.0"
3636
thiserror = "1.0"
3737

3838
[dev-dependencies]
3939
doc-comment = "0.3"
40-
rstest = "0.17"
41-
rstest_reuse = "0.5"
40+
rstest = ">= 0.13, <=0.18"
41+
rstest_reuse = "0.6"
4242
anyhow = "1"
43+
criterion = ">=0.4, <=0.5"
44+
45+
[[bench]]
46+
name = "parsing"
47+
harness = false

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
77

88
Rust version of [libphonenumber](https://github.com/googlei18n/libphonenumber).
9+
We currently require 1.58.0 as minimum supported Rust version (MSRV).
910

1011
## Usage
1112

@@ -20,8 +21,6 @@ phonenumber = "0.3"
2021
The following example parses, validates and formats the given phone number.
2122

2223
```rust,no_run
23-
extern crate phonenumber;
24-
2524
use phonenumber::Mode;
2625
use std::env;
2726

benches/parsing.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
use criterion::{black_box, criterion_group, criterion_main, BenchmarkId, Criterion};
2+
3+
pub fn criterion_benchmark(c: &mut Criterion) {
4+
let cases = [
5+
"+80012340000",
6+
"+61406823897",
7+
"+611900123456",
8+
"+32474091150",
9+
"+34666777888",
10+
"+34612345678",
11+
"+441212345678",
12+
"+13459492311",
13+
"+16137827274",
14+
"+1 520 878 2491",
15+
"+1-520-878-2491",
16+
];
17+
18+
for case in cases {
19+
c.bench_with_input(BenchmarkId::new("parse", case), &case, |b, case| {
20+
b.iter(|| {
21+
let pn = black_box(case);
22+
phonenumber::parse(None, pn)
23+
})
24+
});
25+
}
26+
}
27+
28+
criterion_group!(benches, criterion_benchmark);
29+
criterion_main!(benches);

build.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,6 @@ use std::fs::File;
33
use std::io::{BufReader, BufWriter};
44
use std::path::Path;
55

6-
extern crate quick_xml as xml;
7-
extern crate regex;
8-
extern crate thiserror;
9-
10-
extern crate serde;
11-
#[macro_use]
12-
extern crate serde_derive;
13-
extern crate bincode;
14-
156
use bincode::Options;
167

178
#[path = "src/metadata/loader.rs"]
@@ -21,10 +12,12 @@ mod loader;
2112
mod error;
2213

2314
fn main() {
15+
let pnm_path = "assets/PhoneNumberMetadata.xml";
2416
let metadata = loader::load(BufReader::new(
25-
File::open("assets/PhoneNumberMetadata.xml").expect("could not open metadata file"),
17+
File::open(pnm_path).expect("could not open metadata file"),
2618
))
2719
.expect("failed to load metadata");
20+
println!("cargo:rerun-if-changed={pnm_path}");
2821

2922
let mut out = BufWriter::new(
3023
File::create(Path::new(&env::var("OUT_DIR").unwrap()).join("database.bin"))

examples/test.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use std::env;
22

3-
extern crate phonenumber;
43
use phonenumber::Mode;
54

65
fn main() {

src/carrier.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
use serde_derive::{Deserialize, Serialize};
1516
use std::fmt;
1617

1718
use crate::ParseError;

src/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub const RFC3966_ISDN_SUBADDRESS: &str = ";isub=";
4747

4848
pub const REGION_CODE_FOR_NON_GEO_ENTITY: &str = "001";
4949

50-
lazy_static! {
50+
lazy_static::lazy_static! {
5151
/// Map of country calling codes that use a mobile token before the area code. One example of when
5252
/// this is relevant is when determining the length of the national destination code, which should
5353
/// be the length of the area code plus the length of the mobile token.

src/country.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414

1515
//! Country related types.
1616
17-
use strum::{AsRefStr, EnumString};
18-
17+
use serde_derive::{Deserialize, Serialize};
1918
use std::str;
19+
use strum::{AsRefStr, EnumString};
2020

2121
#[derive(Copy, Clone, Eq, PartialEq, Serialize, Deserialize, Hash, Debug)]
2222
pub struct Code {

src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub enum Parse {
9595
pub enum LoadMetadata {
9696
/// Parsing XML failed, the XML is malformed.
9797
#[error("Malformed Metadata XML: {0}")]
98-
Xml(#[from] xml::Error),
98+
Xml(#[from] quick_xml::Error),
9999

100100
/// Parsing UTF-8 string from XML failed.
101101
#[error("Non UTF-8 string in Metadata XML: {0}")]

0 commit comments

Comments
 (0)