BingoBongo/backend/src/structs.rs

75 lines
1.5 KiB
Rust

use core::fmt;
use serde::Deserialize;
use crate::files;
#[derive(Deserialize)]
pub struct BingoSquare {
option: String,
}
impl BingoSquare {
pub fn new(option: String) -> BingoSquare {
BingoSquare { option }
}
}
#[derive(Deserialize)]
pub struct Meta {
name: String,
reason: String,
}
impl Meta {
pub fn new(name: String, reason: String) -> Meta {
Meta { name, reason }
}
}
#[derive(Deserialize)]
pub struct BingoPool {
meta: Meta,
squares: Vec<BingoSquare>,
}
impl fmt::Display for BingoPool {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "Name: {}\n", self.meta.name).unwrap();
for square in &self.squares {
write!(f, "Square: {}\n", square.option).unwrap();
}
write!(f, "")
}
}
impl BingoPool {
pub fn new() -> BingoPool {
BingoPool {
meta: Meta::new(String::from("Meme"), String::from("Funny")),
squares: Vec::<BingoSquare>::new(),
}
}
pub fn load_from_file(file_path: String) -> BingoPool {
let file_contents = files::load_file_contents(file_path);
let bingopool: BingoPool = toml::from_str(&file_contents).expect("Syntax error in toml");
return bingopool;
}
}
pub struct BingoBoard {
size: i64,
squares: Vec<BingoSquare>,
}
impl BingoBoard {
pub fn new(size: i64) -> BingoBoard {
BingoBoard {
size: size,
squares: Vec::<BingoSquare>::new(),
}
}
pub fn init(&self) {}
}