pub trait Document<T: Id> {
    type Json: Json;
    fn base_url(&self) -> Option<Iri<'_>>;
fn expand_with<'a, C: 'a + ContextMut<T>, L: 'a + Loader>(
        &'a self,
        base_url: Option<Iri<'_>>,
        context: &'a C,
        loader: &'a mut L,
        options: Options
    ) -> BoxFuture<'a, ExpansionResult<T, Self::Json>>
    where
        Self::Json: JsonExpand,
        T: 'a + Send + Sync,
        C: Send + Sync,
        C::LocalContext: From<L::Output> + From<Self::Json>,
        L: Send + Sync,
        L::Output: Into<Self::Json>
; fn expand<'a, C: 'a + ContextMut<T>, L: Loader>(
        &'a self,
        loader: &'a mut L
    ) -> BoxFuture<'a, ExpansionResult<T, Self::Json>>
    where
        Self: Send + Sync,
        Self::Json: JsonExpand,
        C: Send + Sync,
        C::LocalContext: From<L::Output> + From<Self::Json>,
        L: Send + Sync,
        L::Output: Into<Self::Json>,
        T: 'a + Send + Sync
, { ... }
fn compact_with<'a, K: JsonFrom<Self::Json>, C: ContextMutProxy<T>, L: Loader, M1, M2>(
        &'a self,
        base_url: Option<Iri<'a>>,
        context: &'a C,
        loader: &'a mut L,
        options: Options,
        meta_context: M1,
        meta_document: M2
    ) -> BoxFuture<'a, Result<K, Error>>
    where
        Self: Sync,
        Self::Json: JsonExpand + JsonSrc,
        T: 'a + Send + Sync,
        K: JsonFrom<<C::Target as Context<T>>::LocalContext>,
        C: AsJson<<C::Target as Context<T>>::LocalContext, K> + Send + Sync,
        <C::Target as Context<T>>::LocalContext: JsonSrc + From<L::Output> + From<Self::Json>,
        C::Target: Send + Sync,
        L: 'a + Send + Sync,
        M1: 'a + Clone + Send + Sync + Fn(Option<&<<C::Target as Context<T>>::LocalContext as Json>::MetaData>) -> K::MetaData,
        M2: 'a + Clone + Send + Sync + Fn(Option<&<Self::Json as Json>::MetaData>) -> K::MetaData,
        L::Output: Into<Self::Json>
, { ... }
fn compact<'a, C: ContextMutProxy<T> + AsJson<Self::Json, Self::Json>, L: Loader>(
        &'a self,
        context: &'a C,
        loader: &'a mut L
    ) -> BoxFuture<'a, Result<Self::Json, Error>>
    where
        Self: Sync,
        Self::Json: JsonFrom<Self::Json> + JsonExpand + JsonSrc + From<L::Output>,
        <Self::Json as Json>::MetaData: Default,
        T: 'a + Send + Sync,
        C::Target: Context<T, LocalContext = Self::Json>,
        C: Send + Sync,
        C::Target: Send + Sync,
        L: 'a + Send + Sync,
        L::Output: Into<Self::Json>
, { ... } }
Expand description

JSON-LD document.

This trait represent a JSON-LD document that can be expanded into an ExpandedDocument or compacted. It is the main entry point to the JSON-LD API. It is notably implemented for any type implementing the generic_json::Json trait.

Associated Types

Required methods

Document location, if any.

Expand the document with a custom base URL, initial context, document loader and expansion options.

If you do not wish to set the base URL and expansion options yourself, the expand method is more appropriate.

This is an asynchronous method since expanding the context may require loading remote ressources. It returns a boxed Future to the result.

Provided methods

Expand the document.

Uses the given initial context and the given document loader. The default implementation is equivalent to expand_with, but uses the document base_url, with the default options.

This is an asynchronous method since expanding the context may require loading remote ressources. It returns a boxed Future to the result.

Example
use async_std::task;
use json_ld::{Document, context, NoLoader};
use serde_json::Value;

let doc: Value = serde_json::from_str("{
  \"@context\": {
    \"name\": \"http://xmlns.com/foaf/0.1/name\",
    \"knows\": \"http://xmlns.com/foaf/0.1/knows\"
  },
  \"@id\": \"http://timothee.haudebourg.net/\",
  \"name\": \"Timothée Haudebourg\",
  \"knows\": [
    {
      \"name\": \"Amélie Barbe\"
    }
  ]
}").unwrap();
let mut loader = NoLoader::<Value>::new();
let expanded_doc = task::block_on(doc.expand::<context::Json<Value>, _>(&mut loader))?;

Compact the document with a custom base URL, context, document loader and options.

The meta_context parameter is a function to convert the metadata associated to the input context (JSON representation) to K::MetaData. The meta_document parameter is another conversion function for the metadata attached to the document.

Compact the document.

Implementors

Default JSON document implementation.

A Remote document is a document.