Added pool loading
This commit is contained in:
parent
1b5ebc8bc3
commit
a27bb27259
@ -8,18 +8,18 @@ use structs::*;
|
|||||||
fn main() {
|
fn main() {
|
||||||
let config = Config::load();
|
let config = Config::load();
|
||||||
|
|
||||||
let pool = structs::BingoPool::load_from_file(String::from(
|
// let pool = structs::BingoPool::load_from_file(String::from(
|
||||||
"/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools/testdata.toml",
|
// "/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools/testdata.toml",
|
||||||
));
|
// ));
|
||||||
|
|
||||||
// let pools = BingoPools::load_pools();
|
let pools = BingoPools::load_pools();
|
||||||
|
|
||||||
let files = files::list_files(
|
// let files = files::list_files(
|
||||||
String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"),
|
// String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"),
|
||||||
String::from("toml"),
|
// String::from("toml"),
|
||||||
);
|
// );
|
||||||
|
|
||||||
println!("{:?}", files);
|
println!("{}", pools);
|
||||||
|
|
||||||
println!("{}", pool);
|
// println!("{}", pool);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -64,9 +64,35 @@ pub struct BingoPools {
|
|||||||
|
|
||||||
impl BingoPools {
|
impl BingoPools {
|
||||||
pub fn load_pools() -> BingoPools {
|
pub fn load_pools() -> BingoPools {
|
||||||
BingoPools {
|
let pool_files = files::list_files(
|
||||||
pools: Vec::<BingoPool>::new(),
|
String::from("/home/ben/Documents/Projects/rust/BingoBongo/backend/workingdir/pools"),
|
||||||
|
String::from("toml"),
|
||||||
|
);
|
||||||
|
let mut pools = Vec::<BingoPool>::new();
|
||||||
|
for entry in pool_files {
|
||||||
|
pools.push(
|
||||||
|
toml::from_str(files::load_file_contents(entry).as_str())
|
||||||
|
.expect("Failed to parse file"),
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
BingoPools { pools }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl fmt::Display for BingoPools {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "Number of pools: {}\n\n", &self.pools.len()).unwrap();
|
||||||
|
for entry in &self.pools {
|
||||||
|
write!(
|
||||||
|
f,
|
||||||
|
"Pool: {}\nLength: {}\n\n",
|
||||||
|
entry.meta.name,
|
||||||
|
entry.squares.len()
|
||||||
|
)
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
write!(f, "")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
36
backend/workingdir/pools/newdata.toml
Normal file
36
backend/workingdir/pools/newdata.toml
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
[meta]
|
||||||
|
name = 'Test pool 2'
|
||||||
|
description = 'Description of pool'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'First square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Second square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Third square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fourth square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fifth square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fifth square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fifth square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fifth square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fifth square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fifth square'
|
||||||
|
|
||||||
|
[[squares]]
|
||||||
|
option = 'Fifth square'
|
||||||
@ -1,5 +1,5 @@
|
|||||||
[meta]
|
[meta]
|
||||||
name = 'Name of pool'
|
name = 'Test pool'
|
||||||
description = 'Description of pool'
|
description = 'Description of pool'
|
||||||
|
|
||||||
[[squares]]
|
[[squares]]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user