Struct Order

Source
pub struct Order {
    pub order: Items,
    pub menu_items: Items,
    pub cost_for_items: Items,
}

Fields§

§order: Items§menu_items: Items§cost_for_items: Items

Implementations§

Source§

impl Order

Source

pub fn new(menu_items: Items, cost_for_items: Items) -> Self

§This New Func Creates A New Instance
§Example
    use std::collections::HashMap;
    use dit_as_91896::{
        order::Order,
        food::Items
    };

    let my_order: Order = Order::new(
        Items::new(HashMap::new(), HashMap::new(), HashMap::new()),
        Items::new(HashMap::new(), HashMap::new(), HashMap::new())
    );
Source

pub fn order_add(&mut self, item_name: String) -> Result<(), &'static str>

§Add To The Order
§Example
    use map_macro::hash_map;
    use std::collections::HashMap;

    use dit_as_91896::{
        order::Order,
        food::Items
    };

    let menu = Items::new(
        hash_map! {
            String::from("test_food") => 2.0
        },
        HashMap::new(),
        HashMap::new()
    );

    let cost_menu = Items::new(
        hash_map! {
            String::from("test_food") => 1.0
        },
        HashMap::new(),
        HashMap::new()
    );

    let mut my_order: Order = Order::new(
        menu,
        cost_menu
    );

    // adds two of the food.
    my_order.order_add(String::from("test_food")).unwrap();

    my_order.order_add(String::from("test_food")).unwrap();

    let order_output = Items::new(hash_map! { String::from("test_food") => 4.0 }, HashMap::new(), HashMap::new());

    assert!(my_order.order.food == order_output.food);
    assert!(my_order.order.drinks == order_output.drinks);
    assert!(my_order.order.sides == order_output.sides);
Source

pub fn cost_profit(&self) -> Vec<f64>

§Calculate the Cost and profit.

Find for the Customer and the profit for the store.\

Returns: Vec: [ cost_user: f64, profit_store: f64 ]

§Example
    use map_macro::hash_map;
    use std::collections::HashMap;

    use dit_as_91896::{
        order::Order,
        food::Items
    };

    // cost to user
    let menu = Items::new(
        hash_map! {
            String::from("test_food") => 2.0
        },
        HashMap::new(),
        HashMap::new()
    );

    // cost of items for eg "the store"
    let cost_menu = Items::new(
        hash_map! {
            String::from("test_food") => 1.0
        },
        HashMap::new(),
        HashMap::new()
    );

    let mut my_order: Order = Order::new(
        menu,
        cost_menu
    );

    // adds two of the food.
    my_order.order_add(String::from("test_food")).unwrap();

    my_order.order_add(String::from("test_food")).unwrap();

    assert!(my_order.cost_profit() == vec![4.0, 2.0]);

Trait Implementations§

Source§

impl Clone for Order

Source§

fn clone(&self) -> Order

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Display for Order

Source§

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

§Allows Order To Be Printed

Auto Trait Implementations§

§

impl Freeze for Order

§

impl RefUnwindSafe for Order

§

impl Send for Order

§

impl Sync for Order

§

impl Unpin for Order

§

impl UnwindSafe for Order

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dst: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.