코드 4-10 JSON 파일에서 질문을 읽어 저장소에 넣기
use serde::{Serialize, Deserialize};
...
impl Store {
fn new() -> Self {
Store {
questions: Self::init(),
}
}
fn init() -> HashMap<QuestionId, Question> {
let file = include_str!("../questions.json");
serde_json::from_str(file).expect("can't read questions.json")
}
fn add_question(mut self, question: Question) -> Self {
self.questions.insert(question.id.clone(), question);
self
}
}