use serde from rocket_dyn_templates
continuous-integration/drone/push Build is passing Details
continuous-integration/drone/pr Build is passing Details

This commit is contained in:
Dmitry Belyaev 2023-08-05 19:42:19 +03:00
parent 67087e6583
commit a4dd460c37
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
3 changed files with 10 additions and 25 deletions

21
Cargo.lock generated
View File

@ -536,13 +536,13 @@ dependencies = [
[[package]]
name = "filetime"
version = "0.2.21"
version = "0.2.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cbc844cecaee9d4443931972e1289c8ff485cb4cc2767cb03ca139ed6885153"
checksum = "d4029edd3e734da6fe05b6cd7bd2960760a616bd2ddd0d59a0124746d6272af0"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.2.16",
"redox_syscall",
"windows-sys 0.48.0",
]
@ -1204,7 +1204,7 @@ checksum = "93f00c865fe7cabf650081affecd3871070f26767e7b2070a3ffae14c654b447"
dependencies = [
"cfg-if",
"libc",
"redox_syscall 0.3.5",
"redox_syscall",
"smallvec",
"windows-targets 0.48.1",
]
@ -1419,8 +1419,6 @@ dependencies = [
"rand",
"rocket",
"rocket_dyn_templates",
"serde",
"serde_json",
]
[[package]]
@ -1462,15 +1460,6 @@ dependencies = [
"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]]
name = "redox_syscall"
version = "0.3.5"
@ -1890,7 +1879,7 @@ checksum = "5486094ee78b2e5038a6382ed7645bc084dc2ec433426ca4c3cb61e2007b8998"
dependencies = [
"cfg-if",
"fastrand",
"redox_syscall 0.3.5",
"redox_syscall",
"rustix",
"windows-sys 0.48.0",
]

View File

@ -11,8 +11,6 @@ readme = "README.md"
[dependencies]
rand="0.8"
serde="1.0"
serde_json="1.0"
rocket = { version = "=0.5.0-rc.3", features = ["json"] }
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"}

View File

@ -1,6 +1,3 @@
extern crate serde;
extern crate serde_json;
#[macro_use]
extern crate rocket;
@ -8,6 +5,7 @@ use rocket::response::Redirect;
use rocket::State;
use rocket::fs::FileServer;
use rocket_dyn_templates::Template;
use rocket_dyn_templates::tera;
use rand::distributions::Uniform;
use rand::Rng;
@ -37,11 +35,11 @@ impl<T, E> ErrorEmpty for Result<T, E> {
#[derive(Clone)]
struct ArcTemplateData {
value: Arc<serde_json::Value>,
value: Arc<tera::Value>,
}
impl ArcTemplateData {
fn new(value: serde_json::Value) -> ArcTemplateData {
fn new(value: tera::Value) -> ArcTemplateData {
ArcTemplateData {
value: Arc::new(value),
}
@ -94,10 +92,10 @@ fn show_question_details(
match get_question(&data.db, id) {
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() {
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);