Struct Items

Source
pub struct Items {
    pub food: HashMap<String, f64>,
    pub drinks: HashMap<String, f64>,
    pub sides: HashMap<String, f64>,
}

Fields§

§food: HashMap<String, f64>§drinks: HashMap<String, f64>§sides: HashMap<String, f64>

Implementations§

Source§

impl Items

Source

pub fn new( food: HashMap<String, f64>, drinks: HashMap<String, f64>, sides: HashMap<String, f64>, ) -> Self

§New instance function

@prams: food: vector of food items drinks: vector of drinks sides: vector of sides @return: instance of type Items

§Panics

The function panics if the second argument is zero.

    use std::collections::HashMap;
    use map_macro::hash_map;
    use dit_as_91896::food::Items;

    let food: HashMap<String, f64> = hash_map! {
        String::from("0") => 0.0,
    };
    let drinks: HashMap<String, f64> = hash_map! {
        String::from("1") => 1.0,
    };
    let sides: HashMap<String, f64> = hash_map! {
        String::from("2") => 2.0,
    };

    let items: Items = Items::new(food.clone(), drinks.clone(), sides.clone());

    assert!(items.food == food);
    assert!(items.drinks == drinks );
    assert!(items.sides == sides);
Source

pub fn menu_view(&self) -> String

§view the menu in a prety format

no params

returns a String

Trait Implementations§

Source§

impl Clone for Items

Source§

fn clone(&self) -> Items

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 Items

Source§

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

Fmt function allows the struct/type to be printed to the console

    use map_macro::hash_map;
    use dit_as_91896::food::Items;

    let items: Items = Items {
    food: hash_map! {
        String::from("0") => 0.0,
    },
    drinks: hash_map! {
        String::from("1") => 1.0,
    },
    sides: hash_map! {
        String::from("2") => 2.0,
    },
};

assert!(format!("{items}").as_str() == "food: {0: costs $0.00}, drinks: {1: costs $1.00}, sides: {2: costs $2.00}");

Auto Trait Implementations§

§

impl Freeze for Items

§

impl RefUnwindSafe for Items

§

impl Send for Items

§

impl Sync for Items

§

impl Unpin for Items

§

impl UnwindSafe for Items

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.