41 lines
758 B
Rust
41 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()
|
|
}
|
|
}
|