pub use category::Category;
#[derive(PartialEq, Debug)]
pub struct Product {
id: u64,
pub name: String,
price: f64,
category: Category,
}
pub mod category;
impl Product {
fn calculate_tax(&self) -> f64 {
self.price * 0.1
}
pub fn product_price(&self) -> f64 {
self.price + self.calculate_tax()
}
pub fn new(id: u64, name: String, price: f64, category: Category) -> Self {
Product {
id,
name,
price,
category,
}
}
pub fn display_product_info(&self) {
println!("id : {:?} , name : {:?} , category : {:?}, price : {:?}",
self.id,
self.name,
"Electronics",
self.price
)
}
}