use crate::{JsonLdLocatedError, syntax::JsonLdContext};
pub trait JsonLdEmbedContext {
fn embed_context(&mut self, context: &JsonLdContext) -> Result<(), JsonLdLocatedError>;
}
#[cfg(feature = "serde")]
impl JsonLdEmbedContext for json_syntax::JsonValue {
fn embed_context(&mut self, context: &JsonLdContext) -> Result<(), JsonLdLocatedError> {
if let Some(obj) = self.as_object_mut() {
let json_context = json_syntax::to_value(context).unwrap();
if !obj.is_empty()
&& !json_context.is_null()
&& !json_context.is_empty_array_or_object()
{
obj.push_front("@context", json_context);
}
};
Ok(())
}
}