project_my_package/product/
mod.rs1pub use category::Category;
2
3#[derive(PartialEq, Debug)]
5pub struct Product {
6 id: u64,
7 pub name: String,
8 price: f64,
9 category: Category,
10}
11
12mod category;
13
14impl Product {
15 fn calculate_tax(&self) -> f64 {
16 self.price * 0.1
17 }
18
19 pub fn product_price(&self) -> f64 {
20 self.price + self.calculate_tax()
21 }
22
23 pub fn new(id: u64, name: String, price: f64, category: Category) -> Product {
31 Product {
32 id,
33 name,
34 price,
35 category,
36 }
37 }
38}