MobileNetwork

Enum MobileNetwork 

Source
pub enum MobileNetwork {
    Globe(Globe),
    Smart(Smart),
    Sun(Sun),
    TNT(TNT),
    Dito(Dito),
    Invalid(String),
}

Variants§

§

Globe(Globe)

§

Smart(Smart)

§

Sun(Sun)

§

TNT(TNT)

§

Dito(Dito)

§

Invalid(String)

Implementations§

Source§

impl MobileNetwork

Source

pub fn get(number: &str) -> Result<Self, MobileNetworkError>

Examples found in repository?
examples/main.rs (line 25)
6fn main() {
7    // if for some reason the default library prefixes has invalid values you can always reset it
8    reset_dito_prefixes();
9    reset_globe_prefixes();
10    reset_smart_prefixes();
11    reset_sun_prefixes();
12    reset_tnt_prefixes();
13    // if the current prefix isnt supported yet by the library you can always append it on compile time
14    // append new prefixes on different networks
15    append_dito_prefixes(&["0911", "0912"]); // Adding new TNT prefixes
16    append_globe_prefixes(&["0917", "0996"]); // Adding new Globe prefixes
17    append_smart_prefixes(&["0918", "0919"]); // Adding new Smart prefixes
18    append_sun_prefixes(&["0933", "0934"]); // Adding new Sun prefixes
19    append_tnt_prefixes(&["0899", "0900"]); // Adding new Dito prefixes
20
21    // Example phone number to validate
22    let number = "09171234567";
23
24    // Get the network based on the phone number and validate the number
25    match MobileNetwork::get(number) {
26        Ok(network) => {
27            println!("Network identified: {}", network.to_string());
28            match network.validate(number) {
29                Ok(valid) => println!("Validation result: {}", valid),
30                Err(e) => println!("Validation error: {:?}", e),
31            }
32        },
33        Err(e) => println!("Error retrieving network: {:?}", e),
34    }
35}

Trait Implementations§

Source§

impl Display for MobileNetwork

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Validate for MobileNetwork

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.