migrate/rocket/0.5 #3
21
Cargo.lock
generated
21
Cargo.lock
generated
@ -536,13 +536,13 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "filetime"
|
name = "filetime"
|
||||||
version = "0.2.21"
|
version = "0.2.22"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153"
|
checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall 0.2.16",
|
"redox_syscall",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1204,7 +1204,7 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"libc",
|
"libc",
|
||||||
"redox_syscall 0.3.5",
|
"redox_syscall",
|
||||||
"smallvec",
|
"smallvec",
|
||||||
"windows-targets 0.48.1",
|
"windows-targets 0.48.1",
|
||||||
]
|
]
|
||||||
@ -1419,8 +1419,6 @@ dependencies = [
|
|||||||
"rand",
|
"rand",
|
||||||
"rocket",
|
"rocket",
|
||||||
"rocket_dyn_templates",
|
"rocket_dyn_templates",
|
||||||
"serde",
|
|
||||||
"serde_json",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1462,15 +1460,6 @@ dependencies = [
|
|||||||
"getrandom",
|
"getrandom",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "redox_syscall"
|
|
||||||
version = "0.2.16"
|
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
||||||
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
|
|
||||||
dependencies = [
|
|
||||||
"bitflags 1.3.2",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "redox_syscall"
|
name = "redox_syscall"
|
||||||
version = "0.3.5"
|
version = "0.3.5"
|
||||||
@ -1890,7 +1879,7 @@ checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"fastrand",
|
"fastrand",
|
||||||
"redox_syscall 0.3.5",
|
"redox_syscall",
|
||||||
"rustix",
|
"rustix",
|
||||||
"windows-sys 0.48.0",
|
"windows-sys 0.48.0",
|
||||||
]
|
]
|
||||||
|
@ -11,8 +11,6 @@ readme = "README.md"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
rand="0.8"
|
rand="0.8"
|
||||||
serde="1.0"
|
|
||||||
serde_json="1.0"
|
|
||||||
rocket = { version = "=0.5.0-rc.3", features = ["json"] }
|
rocket = { version = "=0.5.0-rc.3", features = ["json"] }
|
||||||
rocket_dyn_templates = { version = "=0.1.0-rc.3", features = ["tera"] }
|
rocket_dyn_templates = { version = "=0.1.0-rc.3", features = ["tera"] }
|
||||||
chgk_ledb_lib = {git = "https://gitea.b4tman.ru/b4tman/chgk_ledb.git", rev="27260695f7", package="chgk_ledb_lib"}
|
chgk_ledb_lib = {git = "https://gitea.b4tman.ru/b4tman/chgk_ledb.git", rev="27260695f7", package="chgk_ledb_lib"}
|
||||||
|
12
src/main.rs
12
src/main.rs
@ -1,6 +1,3 @@
|
|||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate rocket;
|
extern crate rocket;
|
||||||
|
|
||||||
@ -8,6 +5,7 @@ use rocket::response::Redirect;
|
|||||||
use rocket::State;
|
use rocket::State;
|
||||||
use rocket::fs::FileServer;
|
use rocket::fs::FileServer;
|
||||||
use rocket_dyn_templates::Template;
|
use rocket_dyn_templates::Template;
|
||||||
|
use rocket_dyn_templates::tera;
|
||||||
|
|
||||||
use rand::distributions::Uniform;
|
use rand::distributions::Uniform;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
@ -37,11 +35,11 @@ impl<T, E> ErrorEmpty for Result<T, E> {
|
|||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
struct ArcTemplateData {
|
struct ArcTemplateData {
|
||||||
value: Arc<serde_json::Value>,
|
value: Arc<tera::Value>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArcTemplateData {
|
impl ArcTemplateData {
|
||||||
fn new(value: serde_json::Value) -> ArcTemplateData {
|
fn new(value: tera::Value) -> ArcTemplateData {
|
||||||
ArcTemplateData {
|
ArcTemplateData {
|
||||||
value: Arc::new(value),
|
value: Arc::new(value),
|
||||||
}
|
}
|
||||||
@ -94,10 +92,10 @@ fn show_question_details(
|
|||||||
|
|
||||||
match get_question(&data.db, id) {
|
match get_question(&data.db, id) {
|
||||||
Ok(question) => {
|
Ok(question) => {
|
||||||
let mut context = serde_json::to_value(question).expect("question serialize");
|
let mut context = tera::to_value(question).expect("question serialize");
|
||||||
if context.is_object() {
|
if context.is_object() {
|
||||||
let next_id = random_question_id(&data.database_distribution);
|
let next_id = random_question_id(&data.database_distribution);
|
||||||
context["next"] = serde_json::to_value(next_id).expect("question id serialize");
|
context["next"] = tera::to_value(next_id).expect("question id serialize");
|
||||||
}
|
}
|
||||||
|
|
||||||
let value = ArcTemplateData::new(context);
|
let value = ArcTemplateData::new(context);
|
||||||
|
Loading…
Reference in New Issue
Block a user