Struct bill::Product

source ·
pub struct Product<'a> {
    pub name: &'a str,
    pub price: Money,
    pub tax: Tax,
}
Expand description

Describes one particular product. Amount is handled by BillItem

You can write your own product, just implement BillProduct

Fields§

§name: &'a str§price: Money§tax: Tax

Implementations§

source§

impl<'a> Product<'a>

source

pub fn new(name: &'a str, price: Money, tax: f64) -> Self

Instantiates a new Product.

Examples found in repository?
examples/catalogue.rs (line 38)
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
fn main() {
    let coffee = Product::new("Coffee", c(250), 0.19);
    let tee = Product::new("Tea", c(175), 0.19);
    let water = Product::new("Water", c(61), 0.19);
    let applejuice = Product::new("AppleJuice", c(164), 0.19);
    let orangejuice = Product::new("OrangeJuice", c(186), 0.19);
    let bagel = Product::new("Bagel", c(219), 0.19);
    let sandwich = Product::new("Sandwich", c(340), 0.19);
    let pie = Product::new("pie", c(94), 0.19);
    let soup = Product::new("Soup", c(310), 0.19);
    let service = Product::new("Service", c(800), 0.00);

    let mut offer = Bill::new();
    offer.add_item(8., water);
    offer.add_item(4., applejuice);
    offer.add_item(4., orangejuice);
    offer.add_item(40., sandwich);
    offer.add_item(2., service);

    let mut invoice = Bill::new();
    invoice.add_item(2., water);
    invoice.add_item(0., applejuice);
    invoice.add_item(2., orangejuice);
    invoice.add_item(50., sandwich);
    invoice.add_item(2.5, service);

    let mut invoice2 = Bill::new();
    invoice2.add_item(99.0, Product::new("Red Ballons", c(99), 0.19));

    #[cfg(not(feature = "serialization"))]
    {
        print("offer", &offer);
        print("invoice", &invoice);
        print("invoice2", &invoice2);
    }
    #[cfg(feature = "serialization")]
    {
        println!("{}", serde_json::to_string_pretty(&offer).unwrap());
        println!("{}", serde_json::to_string_pretty(&invoice).unwrap());
        println!("{}", serde_json::to_string_pretty(&invoice2).unwrap());
    }
}

Trait Implementations§

source§

impl<'a> BillProduct for Product<'a>

source§

fn price(&self) -> Money

Price in Money
source§

fn name(&self) -> String

A name is a term used for identification.
source§

fn tax(&self) -> Tax

source§

impl<'a> Clone for Product<'a>

source§

fn clone(&self) -> Product<'a>

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<'a> Debug for Product<'a>

source§

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

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

impl<'a> Copy for Product<'a>

Auto Trait Implementations§

§

impl<'a> RefUnwindSafe for Product<'a>

§

impl<'a> Send for Product<'a>

§

impl<'a> Sync for Product<'a>

§

impl<'a> Unpin for Product<'a>

§

impl<'a> UnwindSafe for Product<'a>

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.