2021-11-22 18:58:31 +00:00
|
|
|
use once_cell::sync::Lazy;
|
2021-10-28 15:25:26 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-11-25 17:44:49 +00:00
|
|
|
|
2021-11-22 18:58:31 +00:00
|
|
|
static CONTEXT: Lazy<Vec<serde_json::Value>> = Lazy::new(|| {
|
|
|
|
serde_json::from_str(include_str!("../assets/lemmy/context.json")).expect("parse context")
|
|
|
|
});
|
2021-10-28 15:25:26 +00:00
|
|
|
|
2021-11-19 17:47:06 +00:00
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2021-10-28 15:25:26 +00:00
|
|
|
pub(crate) struct WithContext<T> {
|
|
|
|
#[serde(rename = "@context")]
|
2021-11-27 04:55:33 +00:00
|
|
|
#[serde(deserialize_with = "crate::deserialize_one_or_many")]
|
2021-11-19 17:47:06 +00:00
|
|
|
context: Vec<serde_json::Value>,
|
2021-10-28 15:25:26 +00:00
|
|
|
#[serde(flatten)]
|
|
|
|
inner: T,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> WithContext<T> {
|
|
|
|
pub(crate) fn new(inner: T) -> WithContext<T> {
|
|
|
|
WithContext {
|
2021-11-22 18:58:31 +00:00
|
|
|
context: (*CONTEXT).clone(),
|
2021-10-28 15:25:26 +00:00
|
|
|
inner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub(crate) fn inner(self) -> T {
|
|
|
|
self.inner
|
|
|
|
}
|
2020-11-25 17:44:49 +00:00
|
|
|
}
|