⏪ Revert Json serialization
This commit is contained in:
parent
bb109de59d
commit
9cfada4f5d
2 changed files with 9 additions and 18 deletions
|
|
@ -67,7 +67,6 @@ static-files = "0.2.4"
|
||||||
pagetop-macros = { version = "0.0", path = "helpers/pagetop-macros" }
|
pagetop-macros = { version = "0.0", path = "helpers/pagetop-macros" }
|
||||||
|
|
||||||
serde = { version = "1.0", features = ["derive"] }
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
|
||||||
|
|
||||||
[dependencies.futures]
|
[dependencies.futures]
|
||||||
version = "0.3.30"
|
version = "0.3.30"
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
use crate::base::component::add_base_assets;
|
use crate::base::component::add_base_assets;
|
||||||
|
use crate::concat_string;
|
||||||
use crate::core::component::AnyOp;
|
use crate::core::component::AnyOp;
|
||||||
use crate::core::theme::all::{theme_by_short_name, THEME_DEFAULT};
|
use crate::core::theme::all::{theme_by_short_name, THEME_DEFAULT};
|
||||||
use crate::core::theme::{ComponentsInRegions, ThemeRef};
|
use crate::core::theme::{ComponentsInRegions, ThemeRef};
|
||||||
|
|
@ -7,14 +8,10 @@ use crate::html::{Assets, HeadScript, HeadStyles, JavaScript, StyleSheet};
|
||||||
use crate::locale::{LanguageIdentifier, LANGID_DEFAULT};
|
use crate::locale::{LanguageIdentifier, LANGID_DEFAULT};
|
||||||
use crate::service::HttpRequest;
|
use crate::service::HttpRequest;
|
||||||
use crate::util::TypeInfo;
|
use crate::util::TypeInfo;
|
||||||
use crate::{concat_string, trace};
|
|
||||||
|
|
||||||
use serde::de::DeserializeOwned;
|
|
||||||
use serde::Serialize;
|
|
||||||
use serde_json as json;
|
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
|
|
@ -41,7 +38,7 @@ pub enum AssetsOp {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum ParamError {
|
pub enum ParamError {
|
||||||
NotFound,
|
NotFound,
|
||||||
ParseError(json::Error),
|
ParseError(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ParamError {
|
impl fmt::Display for ParamError {
|
||||||
|
|
@ -66,7 +63,7 @@ pub struct Context {
|
||||||
javascript: Assets<JavaScript>, // JavaScripts.
|
javascript: Assets<JavaScript>, // JavaScripts.
|
||||||
headscript: Assets<HeadScript>, // Scripts in head.
|
headscript: Assets<HeadScript>, // Scripts in head.
|
||||||
regions : ComponentsInRegions,
|
regions : ComponentsInRegions,
|
||||||
params : HashMap<&'static str, json::Value>,
|
params : HashMap<&'static str, String>,
|
||||||
id_counter: usize,
|
id_counter: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -83,7 +80,7 @@ impl Context {
|
||||||
javascript: Assets::<JavaScript>::new(), // JavaScripts.
|
javascript: Assets::<JavaScript>::new(), // JavaScripts.
|
||||||
headscript: Assets::<HeadScript>::new(), // Scripts in head.
|
headscript: Assets::<HeadScript>::new(), // Scripts in head.
|
||||||
regions : ComponentsInRegions::default(),
|
regions : ComponentsInRegions::default(),
|
||||||
params : HashMap::<&str, json::Value>::new(),
|
params : HashMap::<&str, String>::new(),
|
||||||
id_counter: 0,
|
id_counter: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -125,13 +122,8 @@ impl Context {
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_param<T: Serialize>(&mut self, key: &'static str, value: &T) -> &mut Self {
|
pub fn set_param<T: FromStr + ToString>(&mut self, key: &'static str, value: &T) -> &mut Self {
|
||||||
json::to_value(value).map_or_else(
|
self.params.insert(key, value.to_string());
|
||||||
|e| trace::error!("Serialization failed for param {key}: {e}"),
|
|
||||||
|v| {
|
|
||||||
self.params.insert(key, v);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -157,11 +149,11 @@ impl Context {
|
||||||
&self.regions
|
&self.regions
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_param<T: DeserializeOwned>(&self, key: &'static str) -> Result<T, ParamError> {
|
pub fn get_param<T: FromStr + ToString>(&self, key: &'static str) -> Result<T, ParamError> {
|
||||||
self.params
|
self.params
|
||||||
.get(key)
|
.get(key)
|
||||||
.ok_or(ParamError::NotFound)
|
.ok_or(ParamError::NotFound)
|
||||||
.and_then(|v| json::from_value(v.clone()).map_err(ParamError::ParseError))
|
.and_then(|v| T::from_str(v).map_err(|_| ParamError::ParseError(v.clone())))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Context PREPARE.
|
// Context PREPARE.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue