mirror of
https://codeberg.org/takouhai/strongbad_email.git
synced 2024-12-22 11:30:38 -05:00
fix: load directly from file
This commit is contained in:
parent
ab14bfd267
commit
b98a118d82
1 changed files with 4 additions and 7 deletions
11
src/main.rs
11
src/main.rs
|
@ -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();
|
||||||
|
|
Loading…
Reference in a new issue