nyandere 0.1.2

i help with keeping track of purchases. meow
Documentation
use super::super::prelude::*;

#[apply(cmd_args!)]
pub struct CreateConcept {
    #[pos]
    pub name: Name,
    #[named(opt)]
    pub price: Option<Money>,
    #[named(opt)]
    pub gtin: Option<Gtin>,
}

impl Command for CreateConcept {
    type Args = Self;
}

impl Run for CreateConcept {
    fn run(self: Box<Self>, ctx: &mut State) -> Output {
        let Self { name, price, gtin } = *self;
        let concept = Concept {
            name,
            default_price: price,
            gtin,
        };
        // if it has a GTIN, we also need to remember it separately
        // so it is still reachable if shadowed by name later on
        if let Some(gtin) = concept.gtin() {
            ctx.concepts_gtin.insert(gtin, concept.clone());
        }

        ctx.concepts.insert(concept.name().to_owned(), concept);

        None
    }
}