Skip to main content

ContextLoader

Trait ContextLoader 

Source
pub trait ContextLoader {
    // Required method
    fn load<'a>(
        &'a mut self,
        url: &'a str,
    ) -> Pin<Box<dyn Future<Output = Option<String>> + 'a>>;

    // Provided method
    fn load_val<'a>(
        &'a mut self,
        url: &'a str,
    ) -> Pin<Box<dyn Future<Output = Option<JsonLdVal>> + 'a>> { ... }
}
Expand description

Hook for fetching remote JSON-LD context documents asynchronously.

Implement this trait to support @context values that are URLs. The load method receives the URL and should return the raw JSON-LD document content as a string, or None if the document cannot be fetched.

§Example (sync wrapper)

struct MyLoader;
impl ContextLoader for MyLoader {
    fn load<'a>(&'a self, url: &'a str) -> Pin<Box<dyn Future<Output = Option<String>> + 'a>> {
        Box::pin(async move { Some(fetch_remote(url).await) })
    }
}

Required Methods§

Source

fn load<'a>( &'a mut self, url: &'a str, ) -> Pin<Box<dyn Future<Output = Option<String>> + 'a>>

Provided Methods§

Source

fn load_val<'a>( &'a mut self, url: &'a str, ) -> Pin<Box<dyn Future<Output = Option<JsonLdVal>> + 'a>>

Fetch and parse a remote JSON-LD context document, returning its parsed value. The default implementation calls load and parses the result; override this to add caching of parsed values.

Implementors§