fix: load directly from file

This commit is contained in:
Daniel Alejandro Gallegos 2023-11-12 15:29:50 -05:00
parent ab14bfd267
commit b98a118d82
Signed by: taco
GPG key ID: 5A09E616957C4F12

View file

@ -3,14 +3,12 @@ use rand::thread_rng;
use serde::Deserialize; use serde::Deserialize;
use toml; use toml;
static SBEMAILS_FILE: &'static[u8] = include_bytes!("sbemails.toml"); #[derive(Deserialize)]
#[derive(Debug, Deserialize)]
struct Sbemails { struct Sbemails {
emails: Vec<Emails>, emails: Vec<Emails>,
} }
#[derive(Debug, Deserialize)] #[derive(Deserialize)]
struct Emails { struct Emails {
number: u8, number: u8,
title: String, title: String,
@ -18,9 +16,8 @@ struct Emails {
fn main() { fn main() {
println!("Preeeeow, world."); println!("Preeeeow, world.");
let sbemails: Sbemails = toml::from_str( let the_paper = include_str!("sbemails.toml");
std::str::from_utf8(SBEMAILS_FILE).unwrap() let sbemails: Sbemails = toml::from_str(the_paper)
)
.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();