From 161859e103e9cdff76e2dcfbc236cc7dd73b4fb3 Mon Sep 17 00:00:00 2001 From: Ruben De Smet Date: Sun, 7 Jul 2024 16:59:56 +0200 Subject: [PATCH] Return unparseable country code as error instead of silent failure Overrides the behaviour of https://github.com/whisperfish/rust-phonenumber/pull/54 Co-authored-by: Regis David Souza Mesquita Co-authored-by: Raphael Costa --- src/phone_number.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/phone_number.rs b/src/phone_number.rs index 1139520..8907324 100644 --- a/src/phone_number.rs +++ b/src/phone_number.rs @@ -236,8 +236,12 @@ impl<'a> Country<'a> { self.0.code.value() } - pub fn id(&self) -> Option { - self.0.metadata(&DATABASE).and_then(|m| m.id().parse().ok()) + pub fn id(&self) -> Result, crate::error::Parse> { + self.0 + .metadata(&DATABASE) + .map(|m| m.id().parse()) + .transpose() + .map_err(|_e| crate::error::Parse::InvalidCountryCode) } }