backend #4

Merged
benjamyn merged 4 commits from backend into master 2024-11-29 06:15:17 -05:00
8 changed files with 59 additions and 13 deletions
Showing only changes of commit 0a0ca87243 - Show all commits

View File

@ -6,6 +6,7 @@ edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
glob = "0.3.1"
serde = { version = "1.0.215", features = ["serde_derive"] }
serde_json = "1.0.133"
toml = "0.8.19"

View File

@ -1,3 +1,4 @@
use glob::glob;
use std::fs::File;
use std::io::prelude::*;
@ -14,3 +15,20 @@ pub fn load_file_contents(file_path: String) -> String {
}
}
}
pub fn list_files(path: String, extension: String) -> Vec<String> {
let mut tmp_path = path.clone();
let mut files = Vec::<String>::new();
let glob_path = format!("{}/*.{}", tmp_path, extension);
// tmp_path.push_str(&glob_path);
// println!("{}", glob_path);
for entry in glob(&glob_path).unwrap() {
match entry {
Ok(p) => files.push(String::from(p.display().to_string())),
Err(e) => return vec![String::new()],
}
}
return files;
}

View File

@ -9,8 +9,17 @@ fn main() {
let config = Config::load();
let pool = structs::BingoPool::load_from_file(String::from(
"/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/squares/testdata/testdata.toml",
"/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools/testdata.toml",
));
// let pools = BingoPools::load_pools();
let files = files::list_files(
String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"),
String::from("toml"),
);
println!("{:?}", files);
println!("{}", pool);
}

View File

@ -58,6 +58,18 @@ impl BingoPool {
}
}
pub struct BingoPools {
pools: Vec<BingoPool>,
}
impl BingoPools {
pub fn load_pools() -> BingoPools {
BingoPools {
pools: Vec::<BingoPool>::new(),
}
}
}
pub struct BingoBoard {
size: i64,
squares: Vec<BingoSquare>,

View File

@ -0,0 +1,18 @@
[meta]
name = 'Name of pool'
description = 'Description of pool'
[[squares]]
option = 'First square'
[[squares]]
option = 'Second square'
[[squares]]
option = 'Third square'
[[squares]]
option = 'Fourth square'
[[squares]]
option = 'Fifth square'

View File

@ -1,12 +0,0 @@
[meta]
name = 'Test Bingo'
description = 'Because its fucking funny'
[[squares]]
option = 'Code compiles first try and no one believes you'
[[squares]]
option = 'There isnt a crate for that already'
[[squares]]
option = 'Someone tells you to use JS'

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 240 KiB