From ab14bfd267a8e20a53cc1ac7234ae6c0452c91ab Mon Sep 17 00:00:00 2001 From: Daniel Alejandro Gallegos Date: Sun, 12 Nov 2023 15:07:37 -0500 Subject: [PATCH] fix: load file into binary and load from there --- src/main.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main.rs b/src/main.rs index 7e36619..f06425b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,9 +1,10 @@ use rand::seq::SliceRandom; use rand::thread_rng; use serde::Deserialize; -use std::fs; use toml; +static SBEMAILS_FILE: &'static[u8] = include_bytes!("sbemails.toml"); + #[derive(Debug, Deserialize)] struct Sbemails { emails: Vec, @@ -17,9 +18,9 @@ struct Emails { fn main() { println!("Preeeeow, world."); - let toml_file = fs::read_to_string("src/sbemails.toml") - .expect("failed to read sbemails.toml"); - let sbemails: Sbemails = toml::from_str(&toml_file) + let sbemails: Sbemails = toml::from_str( + std::str::from_utf8(SBEMAILS_FILE).unwrap() + ) .expect("failed to deserialize sbemails.toml"); let mut random_number = thread_rng(); let sbemail = sbemails.emails.choose(&mut random_number).unwrap();