split/src/purchase.rs
Aravinth Manivannan 7c777eaa17
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
feat: reuse.software
2023-08-17 02:32:45 +05:30

40 lines
758 B
Rust

// SPDX-FileCopyrightText: 2023 Aravinth Manivannan <realaravinth@batsense.net>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
use std::rc::Rc;
use rust_decimal::prelude::*;
use crate::actor::*;
pub trait Purchasable {
fn cost(&self) -> Decimal;
fn name(&self) -> &str;
fn paid_by(&self) -> Rc<dyn Actor>;
}
pub struct Item {
cost: Decimal,
name: String,
payer: Rc<dyn Actor>,
}
impl Item {
pub fn new(name: String, cost: Decimal, payer: Rc<dyn Actor>) -> Self {
Self { cost, name, payer }
}
}
impl Purchasable for Item {
fn cost(&self) -> Decimal {
self.cost
}
fn name(&self) -> &str {
&self.name
}
fn paid_by(&self) -> Rc<dyn Actor> {
self.payer.clone()
}
}