organization_code/product/
mod.rs1pub use category::Category;
2
3#[derive(PartialEq, Debug)]
4pub struct Product {
5 id: u64,
6 pub name: String,
7 price: f64,
8 category: Category,
9}
10
11pub mod category;
12impl Product {
14 fn calculate_tax(&self) -> f64 {
15 self.price * 0.1
16 }
17
18 pub fn product_price(&self) -> f64 {
19 self.price + self.calculate_tax()
20 }
21 pub fn new(id: u64, name: String, price: f64, category: Category) -> Self {
29 Product {
30 id,
31 name,
32 price,
33 category,
34 }
35 }
36
37 pub fn display_product_info(&self) {
38 println!("id : {:?} , name : {:?} , category : {:?}, price : {:?}",
39 self.id,
40 self.name,
41 "Electronics",
42 self.price
43 )
44 }
45}