37 lines
628 B
Rust
37 lines
628 B
Rust
|
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()
|
||
|
}
|
||
|
}
|