fix: load file into binary and load from there

This commit is contained in:
Daniel Alejandro Gallegos 2023-11-12 15:07:37 -05:00
parent 82aa779331
commit ab14bfd267
Signed by: taco
GPG key ID: 5A09E616957C4F12

View file

@ -1,9 +1,10 @@
use rand::seq::SliceRandom; use rand::seq::SliceRandom;
use rand::thread_rng; use rand::thread_rng;
use serde::Deserialize; use serde::Deserialize;
use std::fs;
use toml; use toml;
static SBEMAILS_FILE: &'static[u8] = include_bytes!("sbemails.toml");
#[derive(Debug, Deserialize)] #[derive(Debug, Deserialize)]
struct Sbemails { struct Sbemails {
emails: Vec<Emails>, emails: Vec<Emails>,
@ -17,9 +18,9 @@ struct Emails {
fn main() { fn main() {
println!("Preeeeow, world."); println!("Preeeeow, world.");
let toml_file = fs::read_to_string("src/sbemails.toml") let sbemails: Sbemails = toml::from_str(
.expect("failed to read sbemails.toml"); std::str::from_utf8(SBEMAILS_FILE).unwrap()
let sbemails: Sbemails = toml::from_str(&toml_file) )
.expect("failed to deserialize sbemails.toml"); .expect("failed to deserialize sbemails.toml");
let mut random_number = thread_rng(); let mut random_number = thread_rng();
let sbemail = sbemails.emails.choose(&mut random_number).unwrap(); let sbemail = sbemails.emails.choose(&mut random_number).unwrap();