practo 0.1.0

Basic math operations
Documentation
enum Conveyance {
    Car(i32),
    Train(i32),
    Air(i32),
}

impl Conveyance {
    fn travel_allowance(&self) -> f32 {
        let allowance = match self {
            Conveyance::Car(miles) => *miles as f32 * 14.0 * 2.0,
            Conveyance::Train(miles) => *miles as f32 * 18.0 * 2.0,
            Conveyance::Air(miles) => *miles as f32 * 30.0 * 2.0,
        };

        allowance
    }
}

#[derive(Debug)]
enum Value {
    Integer(i32),
    Float(f32),
}

/*
enum Option<T> {
    None,
    Some(T),
}
 */

struct Person {
    name: String,
    age: u32,
}

fn square(num: Option<i32>) -> Option<i32> {
    match num {
        Some(number) => Some(number * number),
        None => None,
    }
}

/*
enum Result<T, E> {
    Ok(T),
    Err(E),
}
*/

fn division(divident: f64, divisor: f64) -> Result<f64, String> {
    /*
    if divisor == 0.0 {
        Err(String::from("Error encountered:: DivisionByZero Error"))
    } else {
        Ok(divident / divisor)
    }
    */

    match divisor {
        0.0 => Err(String::from("Error encountered:: DivisionByZero Error")),
        _ => Ok(divident / divisor),
    }
}
fn main() {
    let participant_1 = Conveyance::Air(90);

    // println!("The value of the option is {}", participant_1 as i32);

    println!(
        "The travel allowance for participant_1 is {}",
        participant_1.travel_allowance()
    );

    let some_val = vec![Value::Integer(90), Value::Float(87.6)];

    println!(
        "The value of the integer is {:?} and the float is {:?}",
        some_val[0], some_val[1]
    );

    for i in some_val.iter() {
        match i {
            Value::Integer(num) => println!("The value of the integer is {:?}", num),
            Value::Float(num) => println!("The value of the float is {}", num),
        }
    }

    let mut disease = None;

    disease = Some(String::from("Diabetes"));

    match disease {
        Some(disease_name) => println!("You are suffering from {}", disease_name),
        None => println!("You are healthy"),
    };

    /*
    if let Some(disease_nm) = disease {
        println!("You are ill with {}", disease_nm);
    }
    */

    let s1 = Some("Some String");
    println!(
        "The value of s1 is {:?} and the value of s1 itself after unwrapping is {:?}",
        s1,
        s1.unwrap()
    );

    let person1 = Person {
        name: String::from("Muinde"),
        age: 89,
    };
    let somebody = Some(person1);

    let number = Some(7);
    let square = square(number);
    println!("The square is {}", square.unwrap());
    println!();
    println!("{:?}", division(20.0, 9.1));
    println!("{:?}", division(40 as f64, 0.0));

    let some_vec = vec![5, 5, 3, 2, 4, 2, 2];
    let result = match some_vec.get(5) {
        Some(a) => Ok(a),
        None => Err("The value does not exist"),
    };

    println!("The value of result is {:?}", result);
}