Function flowclib::compiler::loader::load[][src]

pub fn load(url: &str, provider: &dyn Provider) -> Result<Process>

Load a context process definition from url, recursively loading all sub-processes referenced.

The return value is a Result containing the Process, or a String describing the error found while loading.

Example

use provider::content::provider::Provider;
use provider::errors::Result;
use std::env;
use url::Url;

// Clients need to provide a Provider of content for the loader as flowlibc is independent of
// file systems and io.
struct DummyProvider;

// A Provider must implement the `Provider` trait, with the methods to `resolve` a URL and to
// `get` the contents for parsing.
impl Provider for DummyProvider {
    fn resolve_url(&self, url: &str, default_filename: &str, _ext: &[&str]) -> Result<(String, Option<String>)> {
       // Just fake the url resolution in this example
       Ok((url.to_string(), None))
    }

   fn get_contents(&self, url: &str) -> Result<Vec<u8>> {
       // Return the simplest flow definition possible - ignoring the url passed in
       Ok("flow = \"test\"".as_bytes().to_owned())
    }
}

// Create an instance of the `DummyProvider`
let dummy_provider = DummyProvider{};

// load the flow from `url = file:///example.toml` using the `dummy_provider`
flowclib::compiler::loader::load("file:///example.toml", &dummy_provider).unwrap();