sample_shoe_co 0.0.1

A demo crate simulating a shoe company with basic inventory and order processing examples.
Documentation
use std::fmt::{Debug, Display, Formatter, Result};
use crate::{product, warehouse};
pub struct Shoe<SKU: Display> {
    model: String,
    sku: SKU,
    quantity: u32,
}

impl<SKU: Display> Shoe<SKU> {
    pub fn new(model: String, sku: SKU, quantity: u32) -> Self {
        Self {
            model,
            sku,
            quantity,
        }
    }
}

impl<SKU: Display> Drop for Shoe<SKU> {
    fn drop(&mut self) {
        println!(
            "Database Operation for Shoe Inventory on model \"{}\" during drop.",
            self.model
        )
    }
}

impl<SKU: Display> Display for Shoe<SKU> {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
        write!(
            formatter,
            "Model: {}, SKU: {}, Quantity: {}",
            self.model, self.sku, self.quantity
        )
    }
}

impl<SKU: Display> Debug for Shoe<SKU> {
    fn fmt(&self, formatter: &mut Formatter<'_>) -> Result {
        write!(
            formatter,
            "Model: {}, SKU: {}, Quantity: {}",
            self.model, self.sku, self.quantity
        )
    }
}

impl<SKU> product::ProductLine<SKU> for Shoe<SKU>
where
    SKU: Display, // Display is good for the end user, Debug is good for the programmer.
{
    fn update_sku(&mut self, sku: SKU) {
        self.sku = sku;
    }

    fn display(&self) -> String {
        format!(
            "Model: {}, SKU: {}, Quantity: {}",
            self.model, self.sku, self.quantity
        )
    }

    fn get_quantity(&self) -> u32 {
        self.quantity
    }
}

impl<SKU> warehouse::WarehouseItem<SKU> for Shoe<SKU>
where
    SKU: Display, // Display is good for the end user, Debug is good for the programmer.
{
    const MIN_ORDER_SIZE: u32 = 20;

    fn set_quantity(&mut self, amount: u32) {
        self.quantity = amount;
    }

    fn restock(&mut self, amount: u32) {
        self.quantity += amount;
        println!("Restocked {} units of {}.", amount, self.model);
    }

    fn sell(&mut self, amount: u32) {
        if self.quantity >= amount {
            self.quantity -= amount;
            println!("Sold {} units of {}.", amount, self.model);
        } else {
            println!(
                "Not enough {} in stock to sell {} units.",
                self.model, amount
            );
        }
    }
}