3个稳定版本
1.0.2 | 2023年4月23日 |
---|---|
1.0.1 | 2023年4月21日 |
914 在 数据库接口
2.5MB
225 行
OpenTriviaQA数据库的Rust包装器
https://github.com/uberspot/OpenTriviaQA
这是一个围绕OpenTriviaQA数据库的包装器。该库将问题内置到二进制文件中(大约8MB),因此在其他Trivia库无法正常工作的地方非常有用(例如WASM)。
代码示例
// Create the context, loading all trivia questions. Here is also where you specify whether or not you would like questions to repeat themselves
let mut ctx = otqa::TriviaContext::new(false);
// Pick a question at random of a specified category. There are twenty to choose from.
let question = ctx.get_question(otqa::Category::Animals, otqa::Seeding::Random);
// If you wanted to pick a specific question (e.g. if you wanted a custom seeding algorithm), the syntax would look like this:
// let question = ctx.get_question(otqa::Category::Animals, otqa::Seeding::Specific(0));
// It will pick the question of that category at that index, applying a modulo should it overflow the amount of questions
// Here are all fields of questions
println!("{}", question.question);
println!("Category: {:?}", question.category);
for answer in question.answers {
println!("{}", answer);
}
println!("Correct answer: {}", question.correct_answer);