writes down some ideas

This commit is contained in:
2019-06-21 21:49:57 +02:00
parent 3d612f33d7
commit 23adaa3e79
3 changed files with 54 additions and 2 deletions

View File

@@ -2,6 +2,7 @@ use crate::schema::players;
use crate::serde_derive::Serialize;
use crate::*;
/// Representation of a player in database
#[derive(Debug, Queryable, Serialize)]
pub struct Player {
id: i32,
@@ -13,6 +14,32 @@ pub struct Player {
pp: i32,
}
/// The sign of the update
enum WealthUpdateKind {
Income,
Expense,
}
/// Representation of wealth value
type WealthValues = (i32, i32, i32, i32);
/// Data used to update wealth
struct WealthUpdate {
kind: WealthUpdateKind,
values: WealthValues,
}
impl WealthUpdate {
/// Create a new update
fn new(values: WealthValues, kind: WealthUpdateKind) -> Self {
WealthUpdate { kind, values }
}
/// Apply the update to the specified player
fn apply_to(self, player_id: i32) {}
}
/// Representation of a new player record
#[derive(Insertable)]
#[table_name = "players"]
pub struct NewPlayer<'a> {
@@ -24,7 +51,7 @@ pub struct NewPlayer<'a> {
}
impl<'a> NewPlayer<'a> {
fn new(name: &'a str, wealth: Option<(i32, i32, i32, i32)>) -> Self {
fn new(name: &'a str, wealth: Option<WealthValues>) -> Self {
let (cp, sp, gp, pp) = wealth.unwrap_or((0, 0, 0, 0));
NewPlayer {
name,
@@ -35,7 +62,7 @@ impl<'a> NewPlayer<'a> {
}
}
fn insert(&self) -> Result<(), ()> {
fn insert(self) -> Result<(), ()> {
Err(())
}
}