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::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<Emails>,
@ -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();