2021-10-28 15:25:26 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2020-11-25 17:44:49 +00:00
|
|
|
|
2021-10-28 15:25:26 +00:00
|
|
|
lazy_static! {
|
2021-11-19 17:47:06 +00:00
|
|
|
static ref CONTEXT: Vec<serde_json::Value> =
|
2021-11-08 15:04:02 +00:00
|
|
|
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-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 {
|
|
|
|
context: CONTEXT.clone(),
|
|
|
|
inner,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
pub(crate) fn inner(self) -> T {
|
|
|
|
self.inner
|
|
|
|
}
|
2020-11-25 17:44:49 +00:00
|
|
|
}
|