use crate::models::Product; #[derive(Debug, Deserialize)] pub struct ProductPatch { pub id: i32, pub name: Option, pub quantity: Option, pub cents: Option, pub description: Option, pub featured: Option, pub category_path: Option, pub photo_set: Option, } impl ProductPatch { pub fn patch(self, product: &mut Product) { if let Some(name) = self.name { product.name = name; } if let Some(category) = self.category_path { product.category = category; } if let Some(description) = self.description { product.description = description; } product.quantity = self.quantity.unwrap_or(product.quantity); product.cents = self.cents.unwrap_or(product.cents); product.featured = self.featured.unwrap_or(product.featured); } }