diff options
author | David Gay <eapoems@riseup.net> | 2023-10-02 01:14:56 -0400 |
---|---|---|
committer | David Gay <eapoems@riseup.net> | 2023-10-02 01:14:56 -0400 |
commit | 8e50eabaddb292960799af34689b29bd0207bd91 (patch) | |
tree | 6f21687d95932b785349d77fa7150262c4d53ff3 /src | |
parent | ce7263e0fa98daafb84295e75064e6d7efd87ba2 (diff) |
Use include_dir to include all yaml files
Diffstat (limited to 'src')
-rw-r--r-- | src/random_tables.rs | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/random_tables.rs b/src/random_tables.rs index 1d9df02..2428ad2 100644 --- a/src/random_tables.rs +++ b/src/random_tables.rs @@ -3,6 +3,7 @@ use serde_yaml; use std::collections::HashMap; use std::error::Error; use std::string::String; +use include_dir::{include_dir, Dir}; use crate::dice; #[derive(Debug, Deserialize)] @@ -27,10 +28,16 @@ pub struct RandomTables { tables: HashMap<String, RandomTable>, } +const YAML_DIR : Dir = include_dir!("src/data/random_tables/"); + impl RandomTables { pub fn new() -> Result<Self, Box<dyn Error>> { - let tables_yaml = include_str!("data/random_tables/ua_magic_items.yaml"); - let tables: HashMap<String, RandomTable> = serde_yaml::from_str(tables_yaml)?; + let mut tables_yaml = String::new(); + for entry in YAML_DIR.files() { + tables_yaml.push_str(entry.contents_utf8().unwrap()); + } + + let tables: HashMap<String, RandomTable> = serde_yaml::from_str(tables_yaml.as_str())?; Ok(RandomTables { tables }) } |