lemmy/crates/apub/src/context.rs

27 lines
610 B
Rust
Raw Normal View History

2021-11-22 18:58:31 +00:00
use once_cell::sync::Lazy;
use serde::{Deserialize, Serialize};
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")
});
#[derive(Serialize, Deserialize, Debug)]
pub(crate) struct WithContext<T> {
#[serde(rename = "@context")]
context: Vec<serde_json::Value>,
#[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(),
inner,
}
}
pub(crate) fn inner(self) -> T {
self.inner
}
}