diff --git a/src/phone_number/mod.rs b/src/phone_number/mod.rs index 597e87a..7f8c43c 100644 --- a/src/phone_number/mod.rs +++ b/src/phone_number/mod.rs @@ -2,8 +2,8 @@ pub mod operators; use regex::Regex; -const MOBILE_REGEX: &str = r#"^(\+98|98|0098|0)?9(\d{2})\d{7}$"#; -pub const PREFIXES: [&str; 4] = ["+98", "98", "0098", "0"]; +static MOBILE_REGEX: &str = r#"^(\+98|98|0098|0)?9(\d{2})\d{7}$"#; +pub static PREFIXES: [&str; 4] = ["+98", "98", "0098", "0"]; /// This is a simple function that checks if a phone number valid or not /// diff --git a/src/phone_number/operators.rs b/src/phone_number/operators.rs index 2f1943f..e7ce1a7 100644 --- a/src/phone_number/operators.rs +++ b/src/phone_number/operators.rs @@ -1,42 +1,17 @@ -use std::collections::HashMap; +use crate::phone_number::{get_operator_prefix, is_phone_valid}; +use std::borrow::Cow; -#[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum Operators { - ShatelMobile, - MCI, - Irancell, - Taliya, - RightTel, -} - -#[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub enum SimType { - Permanent, - Credit, -} - -#[derive(Debug, Clone, PartialEq)] -#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] -pub struct OperatorDetails<'a> { - pub province: Vec<&'a str>, - pub base: &'a str, - pub model: Option<&'a str>, - pub operator: Operators, - pub sim_types: Vec, -} +pub mod constants { + use super::*; -/// returns operator details for mci -pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { - HashMap::from([ + pub static MCI: &[(&str, OperatorDetails)] = &[ ( "910", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -44,9 +19,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "914", OperatorDetails { base: "آذربایجان غربی", - province: vec!["آذربایجان شرقی", "اردبیل", "اصفهان"], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["آذربایجان شرقی", "اردبیل", "اصفهان"]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -54,9 +29,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "911", OperatorDetails { base: "مازندران", - province: vec!["گلستان", "گیلان"], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["گلستان", "گیلان"]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -64,16 +39,16 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "912", OperatorDetails { base: "تهران", - province: vec![ + province: Cow::Borrowed(&[ "البرز", "زنجان", "سمنان", "قزوین", "قم", "برخی از شهرستان های استان مرکزی", - ], - sim_types: vec![SimType::Permanent], - operator: Operators::MCI, + ]), + sim_types: Cow::Borrowed(&[SimType::Permanent]), + operator: Operator::MCI, model: None, }, ), @@ -81,9 +56,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "913", OperatorDetails { base: "اصفهان", - province: vec!["یزد", "چهارمحال و بختیاری", "کرمان"], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["یزد", "چهارمحال و بختیاری", "کرمان"]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -91,9 +66,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "915", OperatorDetails { base: "خراسان رضوی", - province: vec!["خراسان شمالی", "خراسان جنوبی", "سیستان و بلوچستان"], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["خراسان شمالی", "خراسان جنوبی", "سیستان و بلوچستان"]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -101,9 +76,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "916", OperatorDetails { base: "خوزستان", - province: vec!["لرستان", "فارس", "اصفهان"], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["لرستان", "فارس", "اصفهان"]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -111,9 +86,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "917", OperatorDetails { base: "فارس", - province: vec!["بوشهر", "کهگیلویه و بویر احمد", "هرمزگان"], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["بوشهر", "کهگیلویه و بویر احمد", "هرمزگان"]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -121,9 +96,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "918", OperatorDetails { base: "کرمانشاه", - province: vec!["کردستان", "ایلام", "همدان"], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["کردستان", "ایلام", "همدان"]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -131,9 +106,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "919", OperatorDetails { base: "تهران", - province: vec!["البرز", "سمنان", "قم", "قزوین", "زنجان"], - sim_types: vec![SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["البرز", "سمنان", "قم", "قزوین", "زنجان"]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -141,9 +116,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "990", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -151,9 +126,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "991", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -161,9 +136,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "992", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -171,9 +146,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "993", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -181,9 +156,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "994", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -191,9 +166,9 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "995", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), @@ -201,39 +176,33 @@ pub fn mci<'a>() -> HashMap<&'a str, OperatorDetails<'a>> { "996", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, }, ), - ]) -} + ]; -/// returns operator details for talia -pub fn talia() -> HashMap<&'static str, OperatorDetails<'static>> { - HashMap::from([( + pub static TALIYA: &[(&str, OperatorDetails)] = &[( "932", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::Taliya, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::Taliya, model: None, }, - )]) -} + )]; -/// returns operator details for RightTel -pub fn right_tel() -> HashMap<&'static str, OperatorDetails<'static>> { - HashMap::from([ + pub static RIGHTTEL: &[(&str, OperatorDetails)] = &[ ( "920", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Permanent], - operator: Operators::RightTel, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Permanent]), + operator: Operator::RightTel, model: None, }, ), @@ -241,9 +210,9 @@ pub fn right_tel() -> HashMap<&'static str, OperatorDetails<'static>> { "921", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::RightTel, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::RightTel, model: None, }, ), @@ -251,9 +220,9 @@ pub fn right_tel() -> HashMap<&'static str, OperatorDetails<'static>> { "922", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::RightTel, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::RightTel, model: None, }, ), @@ -261,45 +230,142 @@ pub fn right_tel() -> HashMap<&'static str, OperatorDetails<'static>> { "923", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::RightTel, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::RightTel, model: None, }, ), - ]) -} + ]; -/// returns operator details for irancell -pub fn irancell() -> HashMap<&'static str, OperatorDetails<'static>> { - let basic_model = OperatorDetails { - base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit, SimType::Permanent], - operator: Operators::Irancell, - model: None, - }; - - HashMap::from([ - ("930", basic_model.clone()), - ("933", basic_model.clone()), - ("935", basic_model.clone()), - ("936", basic_model.clone()), - ("937", basic_model.clone()), - ("938", basic_model.clone()), - ("939", basic_model.clone()), - ("901", basic_model.clone()), - ("902", basic_model.clone()), - ("903", basic_model.clone()), - ("905", basic_model.clone()), - ("900", basic_model.clone()), + pub static IRANCELL: &[(&str, OperatorDetails)] = &[ + ( + "930", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "933", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "935", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "936", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "937", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "938", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "939", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "901", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "902", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "903", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "905", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), + ( + "900", + OperatorDetails { + base: "کشوری", + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit, SimType::Permanent]), + operator: Operator::Irancell, + model: None, + }, + ), ( "904", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::Irancell, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::Irancell, model: Some("سیم‌کارت کودک"), }, ), @@ -307,45 +373,132 @@ pub fn irancell() -> HashMap<&'static str, OperatorDetails<'static>> { "941", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::Irancell, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::Irancell, model: Some("TD-LTE"), }, ), - ]) -} + ]; -/// returns operator details for Shatel Mobile -pub fn shatel_mobile() -> HashMap<&'static str, OperatorDetails<'static>> { - HashMap::from([( + pub static SHATELMOBILE: &[(&str, OperatorDetails)] = &[( "998", OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::ShatelMobile, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::ShatelMobile, model: None, }, - )]) + )]; } -/// returns all operators details -pub fn all_operators() -> HashMap<&'static str, OperatorDetails<'static>> { - let mut all_operators = HashMap::new(); +#[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum Operator { + ShatelMobile, + MCI, + Irancell, + Taliya, + RightTel, +} + +#[derive(Debug, Copy, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +pub enum SimType { + Permanent, + Credit, +} + +#[derive(Debug, Clone, PartialEq)] +#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))] +#[cfg_attr(feature = "serde", serde(bound(deserialize = "'de: 'a")))] +pub struct OperatorDetails<'a> { + province: Cow<'a, [&'a str]>, + base: &'a str, + model: Option<&'a str>, + operator: Operator, + sim_types: Cow<'a, [SimType]>, +} + +impl Operator { + pub fn details(&self) -> &'static [(&'static str, OperatorDetails<'static>)] { + match self { + Self::MCI => mci(), + Self::Taliya => talia(), + Self::RightTel => talia(), + Self::Irancell => irancell(), + Self::ShatelMobile => shatel_mobile(), + } + } +} + +impl<'a> OperatorDetails<'a> { + pub fn province_list(&'a self) -> &'a [&'a str] { + &self.province + } + + pub fn base(&self) -> &'a str { + &self.base + } + + pub fn model(&self) -> Option<&'a str> { + self.model + } + + pub fn operator(&self) -> Operator { + self.operator + } + + pub fn sim_type_list(&'a self) -> &'a [SimType] { + &self.sim_types + } +} + +/// returns operator details for mci +#[inline(always)] +pub fn mci() -> &'static [(&'static str, OperatorDetails<'static>)] { + constants::MCI +} - all_operators.extend(mci()); - all_operators.extend(talia()); - all_operators.extend(right_tel()); - all_operators.extend(irancell()); - all_operators.extend(shatel_mobile()); +/// returns operator details for talia +#[inline(always)] +pub fn talia() -> &'static [(&'static str, OperatorDetails<'static>)] { + constants::TALIYA +} - all_operators +/// returns operator details for RightTel +#[inline(always)] +pub fn right_tel() -> &'static [(&'static str, OperatorDetails<'static>)] { + constants::RIGHTTEL +} + +/// returns operator details for irancell +#[inline(always)] +pub fn irancell() -> &'static [(&'static str, OperatorDetails<'static>)] { + constants::IRANCELL +} + +/// returns operator details for Shatel Mobile +#[inline(always)] +pub fn shatel_mobile() -> &'static [(&'static str, OperatorDetails<'static>)] { + constants::SHATELMOBILE +} + +/// returns all operators details +#[inline(always)] +pub fn all_operators() -> impl Iterator)> { + mci() + .iter() + .chain(talia().iter()) + .chain(right_tel().iter()) + .chain(irancell().iter()) + .chain(shatel_mobile().iter()) } /// a list of all available Iran operators prefixes -pub fn prefixs() -> Vec<&'static str> { - all_operators().into_keys().collect() +pub fn prefixes() -> Vec<&'static str> { + all_operators().map(|(key, _)| *key).collect::>() } /// returns operator details of givin prefix for example (912, 919, 913) @@ -353,24 +506,20 @@ pub fn prefixs() -> Vec<&'static str> { /// # Examples /// /// ``` -/// use rust_persian_tools::phone_number::operators::{*}; +/// use rust_persian_tools::phone_number::operators::{get_prefix_details, SimType, Operator}; +/// +/// let details = get_prefix_details("910").expect("910 has details"); +/// assert_eq!(details.base(), "کشوری"); +/// // assert_eq!(details.province_list(), &[]); +/// assert_eq!(details.sim_type_list(), &[SimType::Permanent, SimType::Credit]); +/// assert_eq!(details.operator(), Operator::MCI); /// -/// assert_eq!( -/// get_prefix_details("910"), -/// Some(OperatorDetails { -/// base: "کشوری", -/// province: vec![], -/// sim_types: vec![SimType::Permanent, SimType::Credit], -/// operator: Operators::MCI, -/// model: None, -/// },) -/// ); /// assert_eq!(get_prefix_details("9100"), None); /// ``` -pub fn get_prefix_details(prefix: &str) -> Option { - let mut all_prefixes = all_operators(); - - all_prefixes.remove(prefix) +pub fn get_prefix_details(prefix: &str) -> Option<&OperatorDetails<'static>> { + all_operators() + .find(|(key, _)| key == &prefix) + .map(|(_, details)| details) } /// returns operator details of givin phone number @@ -378,25 +527,22 @@ pub fn get_prefix_details(prefix: &str) -> Option { /// # Examples /// /// ``` -/// use rust_persian_tools::phone_number::operators::{*}; +/// use rust_persian_tools::phone_number::operators::{get_phone_details, SimType, Operator}; /// -/// assert_eq!(get_phone_details("09195431812") , Some(OperatorDetails { -/// base: "تهران", -/// province: vec!["البرز", "سمنان", "قم", "قزوین", "زنجان"], -/// sim_types: vec![SimType::Credit], -/// operator: Operators::MCI, -/// model: None, -/// },)); +/// let details = get_phone_details("09195431812").expect("The number has details"); +/// assert_eq!(details.base(), "تهران"); +/// assert_eq!(details.province_list(), &["البرز", "سمنان", "قم", "قزوین", "زنجان"]); +/// assert_eq!(details.sim_type_list(), &[SimType::Credit]); +/// assert_eq!(details.operator(), Operator::MCI); /// /// assert_eq!(get_phone_details("009195431812") , None); /// ``` -pub fn get_phone_details(phone_number: &str) -> Option { - if !super::is_phone_valid(phone_number) { +pub fn get_phone_details(phone_number: &str) -> Option<&OperatorDetails<'static>> { + if !is_phone_valid(phone_number) { return None; } - let prefix = super::get_operator_prefix(phone_number).unwrap(); - get_prefix_details(prefix) + get_operator_prefix(phone_number).and_then(|prefix| get_prefix_details(prefix)) } #[cfg(test)] @@ -407,22 +553,22 @@ mod test_mobile_operators { fn test_get_phone_prefix_operator() { assert_eq!( get_prefix_details("904"), - Some(OperatorDetails { + Some(&OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Credit], - operator: Operators::Irancell, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::Irancell, model: Some("سیم‌کارت کودک"), },) ); assert_eq!( get_prefix_details("910"), - Some(OperatorDetails { + Some(&OperatorDetails { base: "کشوری", - province: vec![], - sim_types: vec![SimType::Permanent, SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&[]), + sim_types: Cow::Borrowed(&[SimType::Permanent, SimType::Credit]), + operator: Operator::MCI, model: None, },) ); @@ -434,11 +580,11 @@ mod test_mobile_operators { fn test_get_phone_details() { assert_eq!( get_phone_details("09195431812"), - Some(OperatorDetails { + Some(&OperatorDetails { base: "تهران", - province: vec!["البرز", "سمنان", "قم", "قزوین", "زنجان"], - sim_types: vec![SimType::Credit], - operator: Operators::MCI, + province: Cow::Borrowed(&["البرز", "سمنان", "قم", "قزوین", "زنجان"]), + sim_types: Cow::Borrowed(&[SimType::Credit]), + operator: Operator::MCI, model: None, },) );