organization_code/product/
mod.rs

1pub 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;
12///! # Online Business
13impl 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    /// # Example
22    /// ```
23    /// use organization_code::Category;
24    /// use organization_code::Product;
25    /// let some_product : Product = Product::new(1,String::from("Laptop"),799.99,Category::Electonics);
26    /// assert_eq!(some_product.name,String::from("Laptop"));
27    /// ```
28    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}