diff options
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/src/main.rs b/src/main.rs index b0c46c0..252740b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use std::fs; -use std::io::{self, Write}; +use std::io; //use anyhow::Result; use rand::prelude::*; @@ -12,6 +12,7 @@ mod charset; mod datafiles; mod example; mod format; +mod server; use charset::Charset; use datafiles::*; use format::*; @@ -39,9 +40,11 @@ enum Cmd { AddExamples, AddFurigana, Format, + Server, } -fn main() { +#[async_std::main] +async fn main() { let opt = Opt::from_args(); match opt.cmd { @@ -158,7 +161,6 @@ fn main() { } } - save_batches(batches).expect("save_batches"); } Cmd::Format => { @@ -189,12 +191,15 @@ fn main() { format_index(&batches, &kanji_levels).expect("format_index"); format_about().expect("format_about"); } + Cmd::Server => { + server::server_main().await.expect("error in server"); + } } } // ---- -fn read_batches() -> anyhow::Result<Vec<Batch>> { +pub fn read_batches() -> anyhow::Result<Vec<Batch>> { let json = fs::read("data/batches.json")?; Ok(serde_json::from_slice::<Vec<Batch>>(&json)?) } @@ -215,17 +220,17 @@ const CHARS_PER_BATCH: usize = 20; const MAX_NEW_CHARS_PER_EX: usize = 5; #[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq)] -struct Batch { - level: String, - chars: Charset, - chars_p1: Charset, - chars_p2: Charset, - chars_bad: Charset, - examples: Vec<Example>, +pub struct Batch { + pub level: String, + pub chars: Charset, + pub chars_p1: Charset, + pub chars_p2: Charset, + pub chars_bad: Charset, + pub examples: Vec<Example>, #[serde(default)] - extra_vocab: Vec<JlptVocab>, + pub extra_vocab: Vec<JlptVocab>, #[serde(default)] - extra_examples: Vec<Example>, + pub extra_examples: Vec<Example>, } fn gen_batches( |