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>
impl<'a> Product<'a>
sourcepub fn new(name: &'a str, price: Money, tax: f64) -> Self
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());
}
}