project_my_package/product/
mod.rs

1pub use category::Category;
2
3/// Struct for storing product related information.
4#[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    /// # Example
24    /// ```
25    /// use project_my_package::Category;
26    /// use project_my_package::Product;
27    /// let some_product = Product::new(1, String::from("Laptop"), 799.99, Category::Electronics);
28    /// assert_eq!(some_product.name, String::from("Laptop"));
29    /// ```
30    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}