Trait json_ld::Document[][src]

pub trait Document<T: Id> {
    type LocalContext: Local<T>;
    fn base_url(&self) -> Option<Iri<'_>>;
fn expand_with<'a, C: Send + Sync + ContextMut<T>, L: Send + Sync + Loader>(
        &'a self,
        base_url: Option<Iri<'_>>,
        context: &'a C,
        loader: &'a mut L,
        options: Options
    ) -> BoxFuture<'a, Result<ExpandedDocument<T>, Error>>
    where
        C::LocalContext: Send + Sync + From<L::Output> + From<Self::LocalContext>,
        L::Output: Into<Self::LocalContext>,
        T: 'a + Send + Sync
; fn expand<'a, C: 'a + Send + Sync + ContextMut<T>, L: Send + Sync + Loader>(
        &'a self,
        loader: &'a mut L
    ) -> BoxFuture<'a, Result<ExpandedDocument<T>, Error>>
    where
        C::LocalContext: Send + Sync + From<L::Output> + From<Self::LocalContext>,
        L::Output: Into<Self::LocalContext>,
        T: 'a + Send + Sync,
        Self: Sync
, { ... }
fn compact_with<'a, C: ContextMutProxy<T> + Send + Sync + AsJson, L: Send + Sync + Loader>(
        &'a self,
        base_url: Option<Iri<'a>>,
        context: &'a C,
        loader: &'a mut L,
        options: Options
    ) -> BoxFuture<'a, Result<JsonValue, Error>>
    where
        C::Target: Send + Sync + Default,
        <C::Target as Context<T>>::LocalContext: Send + Sync + From<L::Output> + From<Self::LocalContext>,
        L::Output: Into<Self::LocalContext>,
        T: 'a + Send + Sync,
        Self: Sync
, { ... }
fn compact<'a, C: ContextMutProxy<T> + Send + Sync + AsJson, L: Send + Sync + Loader>(
        &'a self,
        context: &'a C,
        loader: &'a mut L
    ) -> BoxFuture<'a, Result<JsonValue, Error>>
    where
        C::Target: Send + Sync + Default,
        <C::Target as Context<T>>::LocalContext: Send + Sync + From<L::Output> + From<Self::LocalContext>,
        L::Output: Into<Self::LocalContext>,
        T: 'a + Id + Send + Sync,
        Self: Sync
, { ... } }
Expand description

JSON-LD document.

This trait represent a JSON-LD document that can be expanded into an ExpandedDocument. It is notabily implemented for the JsonValue type.

Associated Types

The type of local contexts that may appear in the document.

This will most likely be JsonValue.

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, JsonContext, NoLoader};

let doc = json::parse("{
  \"@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 expanded_doc = task::block_on(doc.expand::<JsonContext, _>(&mut NoLoader))?;

Implementations on Foreign Types

Default JSON document implementation.

Returns None.

Use RemoteDocument to attach a base URL to a JsonValue document.

Implementors

A Remote document is a document.